我想获取js文件注释的内容。我尝试使用代码
import re
code = """
/*
This is a comment.
*/
/*
This is another comment.
*/
"""
reg = re.compile("/\*(?P<contents>.*)\*/", re.DOTALL)
matches = reg.search(code)
if matches:
print matches.group("contents")
我得到的结果是
This is a comment.
*/
/*
This is another comment.
我如何单独收到评论?
答案 0 :(得分:6)