时间:2021-05-22
前言
我们在前面的例子里,我们学习使用集合里字符或非集合里的字符,这时都是要把每个字符写出来的,但是有时需要把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')], )结果输出如下:
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文介绍在C#中使用匹配中文的正则表达式,包括纯中文、有中文、中文开头、中文结尾等几个正则表达式示例。在正则表达式中,中文可以通过Unicode编码来确定正则表
本文实例讲述了Python使用正则表达式过滤或替换HTML标签的方法。分享给大家供大家参考,具体如下:python正则表达式关键内容:python正则表达式转义
我们已经了解到MySQL可以通过LIKE...%来进行模糊匹配。MySQL同样也支持其他正则表达式的匹配,MySQL中使用REGEXP操作符来进行正则表达式匹配
下面会举几个在grep命令中使用正则表达式从一个文件中匹配到特定的IP地址。下面的正则表达式将会匹配IPV4的地址。正则表达式匹配IP地址:使用下面的正则表达式
1)正则表达式的使用。复制代码代码如下:#正则表达式的模块importre#正则表达式rePattern='.*[0-9]{4}'pattern=re.comp