Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import re
string = 'banana'
pattern = 'an'
match=(re.search(pattern, string))
#Returns match object
print (match)#Output:<re.Match object; span=(1, 3), match='an'>
#getting the starting index using match.start()
print (match.start()) #Output: 1
#Getting the start and end index in tuple format using match.span()
print (match.span()) #Output: (1,3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment