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实现获取命令行输出结果的方法
Jun 10 Python
无法使用pip命令安装python第三方库的原因及解决方法
Jun 12 Python
python使用xlrd模块读取xlsx文件中的ip方法
Jan 11 Python
Python对象转换为json的方法步骤
Apr 25 Python
python3对接mysql数据库实例详解
Apr 30 Python
Python当中的array数组对象实例详解
Jun 12 Python
处理python中多线程与多进程中的数据共享问题
Jul 28 Python
Win10 安装PyCharm2019.1.1(图文教程)
Sep 29 Python
Python networkx包的实现
Feb 14 Python
Python 判断时间是否在时间区间内的实例
May 16 Python
python 动态绘制爱心的示例
Sep 27 Python
Python 微信公众号文章爬取的示例代码
Nov 30 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 file_exists 检查文件或目录是否存在的函数
2010/05/10 PHP
PHP中error_reporting()函数的用法(修改PHP屏蔽错误)
2011/07/01 PHP
解析func_num_args与func_get_args函数的使用
2013/06/24 PHP
thinkphp验证码的实现(form、ajax实现验证)
2016/07/28 PHP
PHP 文件锁与进程锁的使用示例
2017/08/07 PHP
php用xpath解析html的代码实例讲解
2019/02/14 PHP
Apply an AutoFormat to an Excel Spreadsheet
2007/06/12 Javascript
基于JavaScript实现继承机制之调用call()与apply()的方法详解
2013/05/07 Javascript
node.js中的http.response.setHeader方法使用说明
2014/12/14 Javascript
使用getBoundingClientRect方法实现简洁的sticky组件的方法
2016/03/22 Javascript
Node+Express+MongoDB实现登录注册功能实例
2017/04/23 Javascript
vue 动态绑定背景图片的方法
2018/08/10 Javascript
详解vue使用$http服务端收不到参数
2019/04/19 Javascript
原生js拖拽实现图形伸缩效果
2020/02/10 Javascript
[01:11:37]完美世界DOTA2联赛PWL S2 SZ vs FTD.C 第一场 11.19
2020/11/19 DOTA
Python 字典dict使用介绍
2014/11/30 Python
python使用pymysql实现操作mysql
2016/09/13 Python
浅谈Django自定义模板标签template_tags的用处
2017/12/20 Python
python web.py开发httpserver解决跨域问题实例解析
2018/02/12 Python
pandas值替换方法
2018/07/10 Python
python自动化生成IOS的图标
2018/11/13 Python
python变量赋值方法(可变与不可变)
2019/01/12 Python
Python实现的远程文件自动打包并下载功能示例
2019/07/12 Python
python中的逆序遍历实例
2019/12/25 Python
python内打印变量之%和f的实例
2020/02/19 Python
TensorFlow打印输出tensor的值
2020/04/19 Python
class类在python中获取金融数据的实例方法
2020/12/10 Python
介绍一下grep命令的使用
2012/06/28 面试题
医学生职业规划范文
2014/01/05 职场文书
售后服务承诺书
2014/03/26 职场文书
敬老月活动总结
2014/08/28 职场文书
出租房屋协议书
2014/09/14 职场文书
小学教师工作总结2015
2015/04/07 职场文书
我是特种兵观后感
2015/06/11 职场文书
python区块链实现简版工作量证明
2022/05/25 Python
python中filter,map,reduce的作用
2022/06/10 Python