如何使这个正则表达式跳过Python中的新行?

时间:2012-01-12 02:00:47

标签: python regex

如何在此处加入修饰符,例如“M”?我读到有关修饰符进入“多行”模式?我想在搜索中的任何地方跳过一个新行。

content= re.sub(r'(title href="#_ftnref\d+"><span lang="en-us">)(.{1,4}<)',r'\1xyz<',content)

1 个答案:

答案 0 :(得分:2)

你的正则表达式应该这样编译:

myregex = re.compile('regex-pattern', re.IGNORECASE | re.MULTILINE);
myregex.sub(replacement, target[, count = 0]);

更重要的是:

myregex = re.compile('(title href="#_ftnref\d+"><span lang="en-us">)(.{1,4}<)', re.IGNORECASE | re.MULTILINE);
myregex.sub('\1xyz<', content);

有关详细信息,请参阅here