Python正则表达式中的 compile,search,group,groups 函数的简单说明
2013-03-27 10:05
585 查看
以此为例: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), ...)
里面嵌套的那对括号是用于识别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), ...)
相关文章推荐
- Python正则表达式中的 compile,search,group,groups 函数的简单说明
- Python正则表达式中的 compile,search,group,groups 函数的简单说明
- python3正则表达式简单使用、search()、match()等函数的区别
- python中,有关正则表达式re函数:compile、match、search、findall
- python3正则表达式简单使用、search()、match()等函数的区别
- python使用正则表达式的search()函数实现指定位置搜索功能
- python正则表达式--基本用法和函数(简单实例)
- python里使用正则表达式的search()函数实现指定位置搜索
- python里使用正则表达式的group()函数访问分组的结果
- python里使用正则表达式的groups()函数访问组匹配串
- python中的正则表达式的compile,match,search,sub的使用
- python 正则表达式 groups和group有什么区别
- python 正则表达式,函数说明
- python之正则表达式之简单分割字符串split()函数
- python学习:python中的正则表达式函数match和search()的区别
- 【Python3 爬虫】09_正则表达式(re.math()、re.search()、re.sub()、全局匹配函数)
- Python中正则表达式match()、search()函数及match()和search()的区别详解
- python re模块学习--正则表达式函数
- 正则表达式:python将re转义符包装成普通字符的函数
- Python 正则表达式的简单使用示例