1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import re haystack = "Hello world" needle = 'ello' mo = re.search(needle, haystack) print(mo) # Does not work on python 3.6: # assert isinstance(mo, re.Match) assert mo.start() == 1 assert mo.end() == 5 assert re.escape('python.exe') == 'python\\.exe'