python re group()
来源:互联网 发布:天妒英才 知乎 编辑:程序博客网 时间:2024/05/17 03:22
python group()
正则表达式中,group()用来提出分组截获的字符串,()用来分组
import rea = "123abc456"print re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(0) #123abc456,返回整体print re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(1) #123print re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(2) #abcprint re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(3) #456
究其因
1.正则表达式中的三组括号把匹配结果分成三组
-
group() 同group(0)就是匹配正则表达式整体结果 -
group(1) 列出第一个括号匹配部分,group(2)列出第二个括号匹配部分,group(3) 列出第三个括号匹配部分。
2.没有匹配成功的,re.search()返回None
3.当然郑则表达式中没有括号,group(1)肯定不对了。
分类: Python每日小灶
阅读全文
0 0
- python re group()
- python 详解re模块
- Data Struct \ list - insert - re…
- ORA-00265: instance re…
- Uncaught exception 'Re
- A Web services re…
- GROUP BY的用法
- Python For S60
- python 遍历 字典
- vim for python
- python 网络编程
- PYTHON Tkinter GUI
- Python tuples list
- Python cgi windows
- Python - 基础知识1
- Python - 基础知识2
- Python - 基础知识3
- Python - 网络基础
- 关于selenium IDE找不到元素
- Python中os和shutil模块实用方法集…
- Python 异常处理
- 两个行业的故事:编程语言与富裕国家和发展中国家之间的差异
- python 详解re模块
- python re group()
- HttpUrlConnection的setDoOutput与setDoInput
- python实现简单爬虫功能
- setTimeout,setInterval你不知道的…
- html背景图自适应
- 浏览器console的用法
- BUS HOUND调试USB驱动遇到的错误代码解析
- 命题和命题的否定可以同时成立吗?
- IP问问区县级别IP地址库---使用帮助(上篇)