Python篇----正则表达式语法(基础)
来源:互联网 发布:2017黑马python百度云 编辑:程序博客网 时间:2024/05/22 01:33
1 常用的符号
2 常用的函数
3 代码案例
#-*-coding:utf8-*-#导入re库文件import re# from re import findall,search,Ssecret_code = 'hadkfalifexxIxxfasdjifja134xxlovexx23345sdfxxyouxx8dfse'#.的使用举例# a = 'xy123'# b = re.findall('x...',a)# print b#*的使用举例# a = 'xyxy123'# b = re.findall('x*',a)# print b#?的使用举例# a = 'xy123'# b = re.findall('x?',a)# print b'''上面的内容全部都是只需要了解即可,需要掌握的只有下面这一种组合方式(.*?)'''# #.*的使用举例# b = re.findall('xx.*xx',secret_code)# print b# # #.*?的使用举例# c = re.findall('xx.*?xx',secret_code)# print c#### #使用括号与不使用括号的差别# d = re.findall('xx(.*?)xx',secret_code)# print d# for each in d:# print each# s = '''sdfxxhello# xxfsdfxxworldxxasdf'''## d = re.findall('xx(.*?)xx',s,re.S)# print d#对比findall与search的区别# s2 = 'asdfxxIxx123xxlovexxdfd'# # f = re.search('xx(.*?)xx123xx(.*?)xx',s2).group(2)# # print f# f2 = re.findall('xx(.*?)xx123xx(.*?)xx',s2)# print f2[0][1]#sub的使用举例# s = '123rrrrr123'# output = re.sub('123(.*?)123','123%d123'%789,s)# print output#演示不同的导入方法# info = findall('xx(.*?)xx',secret_code,S)# for each in info:# print each#不要使用compile# pattern = 'xx(.*?)xx'# new_pattern = re.compile(pattern,re.S)# output = re.findall(new_pattern,secret_code)# print output#匹配数字a = 'asdfasf1234567fasd555fas'b = re.findall('(\d+)',a)print b
1 0
- Python篇----正则表达式语法(基础)
- 正则表达式基础(语法)
- 正则表达式基础语法
- 正则表达式基础语法
- 正则表达式基础语法
- 正则表达式基础语法
- 正则表达式基础语法
- 正则表达式基础语法
- Python 正则表达式(基础)
- python基础(正则表达式)
- python正则表达式(基础)
- Python 正则表达式学习(二)正则表达式语法
- Python基础--正则表达式基本语法以及re模块
- JavaScript基础语法---正则表达式
- js正则表达式基础语法
- 正则表达式的基础语法
- 正则表达式的基础语法
- 正则表达式--基础语法总结
- HDU 1257 最少拦截系统(基础DP,贪心)
- linux 开发板(Linux USB Gadget) 模拟u盘
- 黑马程序员------iOS程序必要准备
- installshield通过修改注册表实现windows环境变量且即时生效的方法
- HashMap的实现原理
- Python篇----正则表达式语法(基础)
- bzoj 1433 假期的宿舍(网络流)
- 在Salesforce Apex中动态获取SObject信息
- tomcat启动一闪而过问题
- 使用log4cplus写日志
- windows环境下搭建ffmpeg开发环境
- 运维运营一个网站的经验总结
- 最小生成树Kruskal算法
- Apache Rewrite规则详解