>>> comment =re.compile(r'/\*(.*?)\*/')<br>>>> text1 ='/* this is a comment */'<br>>>> text2 ='''/* this is a<br>... multiline comment */<br>... '''<br>>>><br>>>> comment.findall(text1)<br>[' this isa comment ']<br>>>> comment.findall(text2)<br>[]<br>>>><br>
为了修正这个问题,你可以修改模式字符串,增加对换行的支持。比如:
1
>>> comment =re.compile(r'/\*((?:.|\n)*?)\*/')<br>>>> comment.findall(text2)<br>[' this is a\n multiline comment ']<br>>>><br>