【发布时间】:2021-06-03 20:25:46
【问题描述】:
我有 html 内容 我想对此内容发表评论
content = """<html>
<body>
<!--<h1>test</h1>-->
<!--<div>
<img src='x'>
</div>-->
Blockquote
<!--
<div>
<img src='xe'>
</div>
-->
</body>
</html>"""
我使用这个正则表达式
regex_str = "<!--((\n|\r)+)?((.*?)+((\n|\r)+)?)+-->"
在Python中运行此行时
re.findall(regex_str,content)
成功了
但是在jython 中运行时
出现这个错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/share/java/jython-2.7.2.jar/Lib/re$py.class", line 177, in findall
File "/usr/share/java/jython-2.7.2.jar/Lib/re$py.class", line 242, in _compile
sre_constants.error: nothing to repeat
【问题讨论】:
-
您是否尝试过双重转义反斜杠?
-
你的意思是
(\\.*)对吗? -
如
\\r和\\n请注意,您可以将其写为[\n\r]或双重转义[\\r\\n]或Java 中的\\R -
问题出在这部分,我想
(.*?)+我已经尝试过了,但同样的问题