#!/usr/bin/python import re #import the regular expression module line = "Now we are upgrading the PSI3 program" matchstr = re.search("PSI3", line) print "Match starts at character ", matchstr.start() print "Match ends at character ", matchstr.end() print "Before match: ", line[0:matchstr.start()] print "After match:", line[matchstr.end():]