【发布时间】:2012-12-05 14:08:15
【问题描述】:
我找到了一个可行的解决方案来删除所有 html-tags,如下所示:
<cfset test = rereplace(blah, "<h2[^>]*>", "", "ALL") />
在使用 XMLFormat() 格式化后,我需要生成一个 xml 文件并重命名一些标签。 因此我尝试了以下方法:
<!--- example string --->
<cfset blah = '<h1>title 1</h1>
<h2 style="color: black;">title 2</h2>
<h3>test</h3>' />
<cfset test = rereplace(blah, "<h2[^>]*>", "<title_2>", "ALL") />
这会根据需要更改我的标签,但不会停留在 > 部分?...
我也尝试像 \&lt;h2[^>]*\&gt; 那样逃避 & 符号,但这似乎没有帮助。
【问题讨论】:
-
应该
<cfset test = rereplace(blah, "&lt;h2[^>]*&gt;", "<title_2>", "ALL") />是<cfset test = rereplace(blah, "&lt;h2[^&gt;]*&gt;", "<title_2>", "ALL") /> -
我试过这个,但它不匹配......
-
当前代码中#test# 的实际值是多少?
-
我认为是因为 [^ 只匹配单个字符,而您却很想匹配 4。
-
我认为
test = rereplace(blah, "&lt;h2[^&]*&gt;", "<title_2>", "ALL") />会起作用。我的测试等于&lt;h1&gt;title 1&lt;/h1&gt;<title_2>title 2&lt;/h2&gt;&lt;h3&gt;test&lt;/h3&gt;
标签: xml regex coldfusion replace ampersand