Created
August 14, 2020 14:45
-
-
Save BetterProgramming/195e178ce90df0db15f8bd6acfb5236e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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