# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"[A-Z][a-z]+\s+[A-Z][a-z]+" test_str = ("\n" "\n" "\n" "\n" "\n" "\n" "\n" "
Lorem Ipsum dolor Sit amet
Consectetuer adipiscing elit
Aliquam Tincidunt mauris eu Risus
Vestibulum Auctor Dapibus neque
\n" "\n" "\n" "\"\"\"") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches): matchNum = matchNum + 1 print (match.group()) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.