【发布时间】:2018-07-25 04:20:44
【问题描述】:
我使用question 中提供的答案替换了 pre 标记之外的所有换行符。
\n(?![^<]*<\/pre>)
在 pre 标记中的内容有 括号之前它工作正常。
例如,输入:
<p>Test contennt for regex
with line breaks</p>
<pre>code block
with multi line content
working fine</pre>
<pre class="brush:C#">
test line break before
open paranthesis < is not working fine
line breaks after paranthesis
is accepted
</pre>
输出是
<p>Test contennt for regexwith line breaks</p><pre>code block
with multi line content
working fine</pre><pre class="brush:C#">test line break before open paranthesis < is not working fine
line breaks after paranthesis
is accepted
</pre>
这是不正确的 - 并非所有换行符都被删除。
【问题讨论】:
-
不要使用正则表达式解析 HTML。 stackoverflow.com/a/1732454/1255289
标签: regex regex-negation regex-greedy