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


Posted in Python onOctober 10, 2017

前言

我们在前面的例子里,我们学习使用集合里字符或非集合里的字符,这时都是要把每个字符写出来的,但是有时需要把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编写Linux系统守护进程实例
Feb 03 Python
python读取json文件并将数据插入到mongodb的方法
Mar 23 Python
Python探索之修改Python搜索路径
Oct 25 Python
python计算两个矩形框重合百分比的实例
Nov 07 Python
使用Python将Mysql的查询数据导出到文件的方法
Feb 25 Python
详解Python3中setuptools、Pip安装教程
Jun 18 Python
Python Gitlab Api 使用方法
Aug 28 Python
python爬虫 Pyppeteer使用方法解析
Sep 28 Python
Python 实现一行输入多个数字(用空格隔开)
Apr 29 Python
基于python实现上传文件到OSS代码实例
May 09 Python
python 制作一个gui界面的翻译工具
May 14 Python
pytorch 预训练模型读取修改相关参数的填坑问题
Jun 05 Python
python利用正则表达式排除集合中字符的功能示例
Oct 10 #Python
python 上下文管理器使用方法小结
Oct 10 #Python
python中如何使用正则表达式的集合字符示例
Oct 09 #Python
python中如何使用正则表达式的非贪婪模式示例
Oct 09 #Python
Python 多进程和数据传递的理解
Oct 09 #Python
Python 加密的实例详解
Oct 09 #Python
Python 3实战爬虫之爬取京东图书的图片详解
Oct 09 #Python
You might like
PHP独立Session数据库存储操作类分享
2014/06/11 PHP
php计算函数执行时间的方法
2015/03/20 PHP
关于ThinkPHP中的异常处理详解
2018/05/11 PHP
JavaScript Event学习第十一章 按键的检测
2010/02/10 Javascript
JavaScript阻止事件冒泡示例分享
2014/12/28 Javascript
jQuery实现复选框批量选择与反选的方法
2015/06/17 Javascript
jQuery地图map悬停显示省市代码分享
2015/08/20 Javascript
前端设计师们最常用的JS代码汇总
2016/09/25 Javascript
JavaScript中this的用法实例分析
2016/12/19 Javascript
JS数组降维的实现Array.prototype.concat.apply([], arr)
2020/04/28 Javascript
[02:56]DOTA2上海特锦赛小组赛解说FreeAgain采访花絮
2016/02/27 DOTA
Python异常处理总结
2014/08/15 Python
Python原始字符串与Unicode字符串操作符用法实例分析
2017/07/22 Python
python3中的md5加密实例
2018/05/29 Python
python 移除字符串尾部的数字方法
2018/07/17 Python
python如何求解两数的最大公约数
2018/09/27 Python
一步步教你用python的scrapy编写一个爬虫
2019/04/17 Python
python 环境搭建 及python-3.4.4的下载和安装过程
2019/07/20 Python
python性能测量工具cProfile使用解析
2019/09/26 Python
使用python模拟高斯分布例子
2019/12/09 Python
python如何实现不用装饰器实现登陆器小程序
2019/12/14 Python
python单例设计模式实现解析
2020/01/07 Python
python selenium操作cookie的实现
2020/03/18 Python
解决pyPdf和pyPdf2在合并pdf时出现异常的问题
2020/04/03 Python
Python如何使用vars返回对象的属性列表
2020/10/17 Python
abstract 可以和 virtual 一起使用吗?可以和 override 一起使用吗?
2012/10/15 面试题
前台文员个人求职信范文
2014/01/05 职场文书
单位单身证明范本
2014/01/11 职场文书
幼儿园新年寄语
2014/04/03 职场文书
全国税务系统先进集体事迹材料
2014/05/19 职场文书
主要负责人任命书
2014/06/06 职场文书
信仰心得体会
2014/09/05 职场文书
大学拉赞助协议书范文
2014/09/26 职场文书
社区服务活动感想
2015/08/11 职场文书
成功的商业计划书这样写才最靠谱
2019/07/12 职场文书
apache ftpserver搭建ftp服务器
2022/05/20 Servers