以下是XML示例:
<Comment>10 < 100</Comment>
我希望能够正确识别内部的
<
,以便能够将其删除,但我希望保留所有其他内容不变。我假设这将涉及某种[?]选项,但在rubular上进行实验时我还没有成功找到解决方法。
注意:我们正在使用XML解析器rexml,但它无法处理上述情况。相反,Nokogiri无法处理内容中的&符号。
以下是XML示例:
<Comment>10 < 100</Comment>
<
,以便能够将其删除,但我希望保留所有其他内容不变。>
跟随的<
:result = subject.gsub(/<(?![^<>]*>)/, '<')
解释:
< # Match a <
(?! # only if the following regex can't match here:
[^<>]* # any number of characters except angle brackets
> # followed by a closing angle bracket.
) # (End of negative lookahead assertion)