好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python使用正则表达式连接符的示例代码

在正则表达式中,匹配数字或者英文字母的书写非常不方便。因此,正则表达式引入了连接符“-”来定义字符的范围,下面这篇文章主要给大家介绍了关于python中如何使用正则表达式的连接符的相关资料,需要的朋友可以参考下。

#python 3.6 
#蔡军生 
#http://blog.csdn.net/caimouse/article/details/51749579 
# 
from re_test_patterns import test_patterns 
 
test_patterns( 
 'This is some text -- with punctuation.', 
 [('[a-z]+', 'sequences of lowercase letters'), 
  ('[A-Z]+', 'sequences of uppercase letters'), 
  ('[a-zA-Z]+', 'sequences of letters of either case'), 
  ('[A-Z][a-z]+', 'one uppercase followed by lowercase')], 
) 
'[a-z]+' (sequences of lowercase letters)


 'This is some text -- with punctuation.'
 .'his'
 .....'is'
 ........'some'
 .............'text'
 .....................'with'
 ..........................'punctuation'


'[A-Z]+' (sequences of uppercase letters)


 'This is some text -- with punctuation.'
 'T'


'[a-zA-Z]+' (sequences of letters of either case)


 'This is some text -- with punctuation.'
 'This'
 .....'is'
 ........'some'
 .............'text'
 .....................'with'
 ..........................'punctuation'


'[A-Z][a-z]+' (one uppercase followed by lowercase)


 'This is some text -- with punctuation.'
 'This' 

总结

以上就是python使用正则表达式连接符的示例代码的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于python使用正则表达式连接符的示例代码的详细内容...

  阅读:42次