【发布时间】:2012-10-20 02:52:37
【问题描述】:
我想使用 python 获取 js 文件中多行 cmets 的内容。
我试过这个代码示例
import re
code_m = """
/* This is a comment. */
"""
code_s = "/* This is a comment*/"
reg = re.compile("/\*(?P<contents>.*)\*/", re.DOTALL + re.M)
matches_m = reg.match(code_m)
matches_s = reg.match(code_s)
print matches_s # Give a match object
print matches_m # Gives None
我得到matches_m 为None。但是matches_s 有效。我在这里错过了什么?
【问题讨论】: