- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
--> Blockquote --> """ 我使用这个正则表达式 rege-6ren">
我有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
最佳答案
使用
<!--[\n\r]*([\w\W]*?)[\n\r]*-->
参见 regex proof .
解释
--------------------------------------------------------------------------------
<!-- '<!--'
--------------------------------------------------------------------------------
[\n\r]* any character of: '\n' (newline), '\r'
(carriage return) (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[\w\W]*? any character of: word characters (a-z,
A-Z, 0-9, _), non-word characters (all
but a-z, A-Z, 0-9, _) (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
[\n\r]* any character of: '\n' (newline), '\r'
(carriage return) (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
--> '-->'
关于python - sre_constants.error : nothing to repeat in jython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67828254/
我正在使用正则表达式,但出现错误: Traceback (most recent call last): File "tokennet.py", line 825, in RunIt(C
我正在使用正则表达式,但出现错误: Traceback (most recent call last): File "tokennet.py", line 825, in RunIt(C
我有html内容我想从这个内容中获得评论 content = """ test--> --> Blockquote --> """ 我使用这个正则表达式 rege
我正在尝试匹配输出变量中的数据,正在寻找匹配 * 之后的单词,正在尝试以下方式但遇到错误,如何解决? import re output = """test * Peace
我在使用看似简单的 Python 正则表达式时遇到了问题。 # e.g. If I wanted to find "mark has wonderful kittens, but they're mi
以下是错误信息: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/re.py"
我在从 pandas 数据框中删除停用词时遇到问题。我的代码是这样的: for word in stopwords: df['name'] = df['name'].str.replace(wor
我正在尝试使用此正则表达式从另一个字符串获取 JSON 字符串: YAHOO.Finance.SymbolSuggest.ssCallback\((.*?)\) 它适用于 regex101.com ,
我试图匹配 + 之间的所有子字符串和 h ,例如 +abcd1234h . 代码如下: match = re.match(r'.*+(.*)h.*',line) 当我运行我的代码时,发生如下错误: F
所以我正在对某些东西进行一些测试,我需要一种将字符串分成两个组的方法。 (例如 'abcdef' => ['ab','cd','ef']) 我正在尝试使用正则表达式模式来执行此操作 ([^]{2})。
我写了一个Python正则表达式。 import re nt = re.sub('NT:\s*[^,)]*',r'\1', message) 消息包含数据。 (NT:167 毫秒,ST:2509 毫秒
这个错误的原因可能是什么? File "/pga/mcad/install/python/python-2.7.6.9/linux/RH6/lib/python2.7/multiprocessing/
这是我的正则表达式: (?P=[a-zæøå ]+)(?:[ ]+)(?P=\d+)(?:[ ]+),(?:[ ]+)(?P=\d{1,4})(?:[ ]+)(?P=[a-zæøå ]+) 所有组名都
我正在使用 Pandas 。我已经下载了成人数据集并将其转换为 csv 文件,现在我尝试使用 read_csv 函数读取 csv 文件,但出现以下错误: sre_constants.error: n
我知道已经有几个关于这个主题的问题,但没有一个能帮助我解决我的问题。 我必须替换 CSV 文档中的姓名,当他们跟随标签 {SPEAKER} 或 {GROUP OF SPEAKERS} 时。 代码 我的
我是一名优秀的程序员,十分优秀!