好得很程序员自学网

<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.', 
 [('[^-. ]+', 'sequences without -, ., or space')], 
) 
'[^-. ]+' (sequences without -, ., or space)

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

在这个例子里,就把划线、句号、空格(-,., ,)等字符排除在外。

总结

以上就是python如何使用正则表达式排除集合中字符的功能详解的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于python如何使用正则表达式排除集合中字符的功能详解的详细内容...

  阅读:48次