用法:
Match.start([group])Match.end([group])返回与
group匹配的子字符串的开始和结束的索引;group默认为零(表示整个匹配的子字符串)。如果group存在但对匹配没有贡献,则返回-1。对于匹配对象m和确实有助于匹配的组g,组g匹配的子字符串(相当于m.group(g))是m.string[m.start(g):m.end(g)]请注意,如果
group匹配空字符串,则m.start(group)将等于m.end(group)。例如,m = re.search('b(c?)', 'cba'),m.start(0)为 1,m.end(0)为 2,m.start(1)和m.end(1)均为 2,m.start(2)引发IndexError异常。从电子邮件地址中删除
remove_this的示例:>>> email = "tony@tiremove_thisger.net" >>> m = re.search("remove_this", email) >>> email[:m.start()] + email[m.end():] 'tony@tiger.net'
相关用法
- Python re.Match.groupdict用法及代码示例
- Python re.Match.group用法及代码示例
- Python re.Match.groups用法及代码示例
- Python re.Match.__getitem__用法及代码示例
- Python Regex re.MatchObject.groups()用法及代码示例
- Python Regex re.MatchObject.groupdict()用法及代码示例
- Python re.compile用法及代码示例
- Python re.fullmatch()用法及代码示例
- Python re.split用法及代码示例
- Python re.Pattern.match用法及代码示例
- Python re.Pattern.search用法及代码示例
- Python re.escape用法及代码示例
- Python re.search() vs re.match()用法及代码示例
- Python re.sub用法及代码示例
- Python re.findall用法及代码示例
- Python re.Pattern.fullmatch用法及代码示例
- Python re.X用法及代码示例
- Python Numpy recarray.tostring()用法及代码示例
- Python reduce()用法及代码示例
- Python response.status_code用法及代码示例
注:本文由纯净天空筛选整理自python.org大神的英文原创作品 re.Match.start。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
