The thing is that the (\=|...) group is not really part of the match. I think this gives you more the idea what I want reo = re.compile( r'(\=|.)...' ); while True mo = reo.search(text,pos) if not mo: break if text[mo.start()] == '\\' # a pseudo match. continue after the backslash else # a real match. continue after the match