Python正则表达式中的 compile,search,group,groups 函数的简单说明
2017-06-28 21:54
645 查看
以此为例:regex = re.compile('(.∗)')
里面嵌套的那对括号是用于识别group的,所以至多有group(1);
compile是编译正则表达式,生成pattern对象;
pattern.search(S)就是在字符串S中寻找匹配之前生成pattern的子串;
而group和groups是两个不同的函数:
一般,m.group(N) 返回第N组括号匹配的字符。
而m.group() == m.group(0) == 所有匹配的字符,与括号无关,这个是API规定的。
m.groups() 返回所有括号匹配的字符,以tuple格式。
m.groups() == (m.group(1), m.group(2), ...)
转载地址http://blog.csdn.net/cnmilan/article/details/8725094
值得学习的文章
Python正则表达式指南
里面嵌套的那对括号是用于识别group的,所以至多有group(1);
compile是编译正则表达式,生成pattern对象;
pattern.search(S)就是在字符串S中寻找匹配之前生成pattern的子串;
而group和groups是两个不同的函数:
一般,m.group(N) 返回第N组括号匹配的字符。
而m.group() == m.group(0) == 所有匹配的字符,与括号无关,这个是API规定的。
m.groups() 返回所有括号匹配的字符,以tuple格式。
m.groups() == (m.group(1), m.group(2), ...)
转载地址http://blog.csdn.net/cnmilan/article/details/8725094
值得学习的文章
Python正则表达式指南
相关文章推荐
- Python正则表达式中的 compile,search,group,groups 函数的简单说明
- Python正则表达式中的 compile,search,group,groups 函数的简单说明
- python3正则表达式简单使用、search()、match()等函数的区别
- python中,有关正则表达式re函数:compile、match、search、findall
- python3正则表达式简单使用、search()、match()等函数的区别
- python中的正则表达式的compile,match,search,sub的使用
- python 正则表达式 groups和group有什么区别
- 【Python3 爬虫】09_正则表达式(re.math()、re.search()、re.sub()、全局匹配函数)
- python使用正则表达式的search()函数实现指定位置搜索功能
- Python中正则表达式match()、search()函数及match()和search()的区别详解
- python之正则表达式之简单分割字符串split()函数
- python里使用正则表达式的groups()函数访问组匹配串
- python里使用正则表达式的group()函数访问分组的结果
- python正则表达式--基本用法和函数(简单实例)
- python 正则表达式,函数说明
- python学习:python中的正则表达式函数match和search()的区别
- python里使用正则表达式的search()函数实现指定位置搜索
- Python 正则表达式中的函数
- PYTHON正则表达式 re模块使用说明
- python正则表达式替换函数中的回调函数