- span() used in regular expression function in python, which find the upper and lower index of the match pattern in the string.
Syntax-
x=re.search(pattern,string)
x.span()
Example-
string is s="This is string"
x=re.search('is',s)
x.span() will return (5,7)
program-
#import the re module
import re
#Given string is
str = "What is programming language"
#index range of 'is'
x = re.search('is', str)
print(x.span())
#index range of 'in'
x = re.search('in', str)
print(x.span())
#index range of 'ing'
x = re.search('ing', str)
print(x.span())
(5, 7)
(16, 18)
(16, 19)