>>> b = re.compile('(\n+)?=item', re.IGNORECASE) >>> c = 'hello how are you \n\nITeM 84.2 rofl yo' >>> b.match(c) >>> Correction: >>> b = re.compile('(\n+)(?=item)', re.IGNORECASE) >>> print b.split(c) ['hello how are you ', '\n\n', 'ITeM 84.2 rofl yo']