用法:
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
