regular expressions finditer -this returns an iterator of match objects that we can loop throughlike belowfor in re finditer( '([ab])(\ '' + ')print( group( ) note that this is little more general than the findall function in that findall returns the matching stringswhereas finditer returns something like list of match objectswhich give us access to group information compile -if you are going to be reusing the same patternyou can save little time by first compiling the patternas shown belowpattern re compile( '[ab]\ 'pattern sub''' 'pattern sub' '' ' when you compile an expressionfor many of the methods you can specify optional starting and ending indices in the string here is an examplepattern re compile( '[ab]\ 'pattern findall' + + + ', , [' ' examples roman numerals numbers here we use regular expressions to convert roman numerals into ordinary import re ' ': 'cm ': ' ': 'cd ': ' ': 'xc ': ' ': 'xl ': ' ': 'ix ': ' ': 'iv ': ' ': pattern re compile( """(? ( { , })(cm)(cd)?( )?( { , }(xc)?(xl)?( )?( { , }(ix)?(iv)?( )?( { , })"""num input'enter roman numeral'upper( pattern match(numsum for in groups()