How to find start and end index of a word in a string with Python

1 Answer

0 votes
import re      

word = 'programming'
s = 'Python is a programming language that lets you work quickly'      

match = re.search(word, s)  

st = match.start()      
en = match.end()     

print('Found from index {} to index {}'.format(st, en))


'''
run:

Found from index 12 to index 23

'''

 



answered Apr 27, 2019 by avibootz
...