2014-05-25 72 views
0

我使用Python和我有字符串看起来喜欢这样的:如何匹配mediawiki框中包含换行符的字符串?

anything include {{infobox notperson anything include new line}} 
anything 
{{infobox person anything 
many new lines and any charachter 
}} 
anything include {{infobox notperson anything include new line}} 

,我想正则表达式这得到整个信息框人面积从{{信息框人到第一}}字符,是信息框区域的结尾。我应该使用哪种正则表达式?

回答

0

您需要使用re.DOTALL标志为了让.匹配换行符:https://docs.python.org/release/3.1.3/library/re.html#re.DOTALL

这就是你要找的正则表达式:

re.compile("\{\{infobox person[^\}]*\}\}",re.DOTALL) 

编辑:为杰里指出,由于[^\}]已经匹配换行符,所以不需要使用DOTALL

+0

Err ...''[^ \}] *'不匹配换行're.DOTALL' ... – Jerry

+0

它的工作原理,但有没有非python,只有正则表达式? – user3649714

+0

@杰里是的,它的工作原理没有dotall :)感谢的人。 – user3649714

相关问题