Python重新匹配带有空格和换行符的空间

2024-10-03 21:26:51 发布

您现在位置:Python中文网/ 问答频道 /正文

html6="""
<p<ins style="background:#e6ffe6;">re><code</ins>>
int aint bint c<ins style="background:#e6ffe6;"></code></ins></p<ins style="background:#e6ffe6;">re</ins>><p>int d</p>
"""

Html6和Html7是一样的,只是Html7有“\n”

^{pr2}$

html6和html7都不匹配?,但如果我将“\n”替换为“”,则两者都将非常相似。在

print re.match(p_to_pre_code_pattern,html6.replace("\n",""))    
print re.match(p_to_pre_code_pattern,html7.replace("\n",""))

我想知道在不调用replace("\n",""))的情况下,如何更改将同时匹配html6和html7的p_to_pre_code_pattern?在


Tags: torestylecodeprereplaceintpattern
1条回答
网友
1楼 · 发布于 2024-10-03 21:26:51

可能您在调用re.DOTALL时错过了re.compile(..., re.VERBOSE|re.DOTALL)标志

re.S 
re.DOTALL 

Make the '.' special character match any character at all, including a newline;
without this flag, '.' will match anything except a newline.

相关问题 更多 >