我想获取 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.
如何单独获取评论?