全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 数据分析与数据挖掘
1008 0
2021-05-12
CDA人工智能学院致力于以优质的人工智能在线教育资源助力学员的DT职业梦想!课程内容涵盖数据分析机器学习深度学习人工智能tensorFlowPyTorch知识图谱等众多核心技术及行业案例,让每一个学员都可以在线灵活学习,快速掌握AI时代的前沿技术。PS:私信我即可获取CDA会员1个月免费试听机会
我们在前面的例子里,我们学习使用集合里字符或非集合里的字符,这时都是要把每个字符写出来的,但是有时需要把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'
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值.



扫码关注CDA公众号,即可获取最新版数据分析题库大全CDA免费精品课70+


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群