import re s = "a vfewfwefdd\n 12344N " pattern = re.compile("a(.*)n", re.S|re.I) print(pattern.findall(s))