Python ProgrammingPython Programming

Example of string find in Python

import re

text = 'This is sample text to test if this pythonic '\
       'program can serve as an indexing platform for '\
       'finding words in a paragraph. It can give '\
       'values as to where the word is located with the '\
       'different examples as stated'

find_the_word = re.finditer('as', text)

for match in find_the_word:
    print('start {}, end {}, search string \'{}\''.
          format(match.start(), match.end(), match.group()))
Output
start 63, end 65, search string 'as'
start 140, end 142, search string 'as'
start 200, end 202, search string 'as'