python中使用正则表达式的连接符示例代码
2017-10-10 08:56
633 查看
前言
我们在前面的例子里,我们学习使用集合里字符或非集合里的字符,这时都是要把每个字符写出来的,但是有时需要把26个小写字母都放到集合里,那么按集合的方法,得输入26次,一个一个键入去,这样比较花时间,也容易出错,那么有没有更好的方法呢?这个是有的,就是使用正则表达式的连接符的功能:-,比如表示26个小写字符,就使用[a-z]就可以了。
本文详细的给大家介绍了关于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中如何使用正则表达式的非贪婪模式示例
- Python使用中文正则表达式匹配指定中文字符串的方法示例
- JavaScript 使用正则表达式进行表单验证的示例代码
- Python 正则表达式的简单使用示例
- Python3使用正则表达式爬取内涵段子示例
- python使用正则表达式匹配字符串开头并打印示例
- python里使用正则表达式的连接符
- 使用Python正则表达式RE从CSDN博客源代码中匹配出博客信息
- python中如何使用正则表达式的集合字符示例
- Python使用正则表达式抓取网页图片的方法示例
- JavaScript 使用正则表达式进行表单验证的示例代码
- python利用正则表达式搜索单词示例代码
- [导入][原创]使用正则表达式找出HTML代码内所有IMG图片的SRC链接地址
- 在python 中使用正则表达式
- 正则表达式练习使用代码
- Python天天美味(15) - Python正则表达式操作指南(re使用)(转)
- python正则表达式分析新浪网天气预报,通过pyfetion发送短信的代码
- 比较详细Python正则表达式操作指南(re使用)
- 使用Python进行AES加密和解密的示例代码