我希望在ColdFusion中使用regex从字符串的开头删除任何<br>
,<br />
或<br/>
标记。
初始文字 -
<br /><br>Philosophy Now is a lively and readable magazine for everyone interested in ideas.
<br> This is a test
最终文本 -
Philosophy Now is a lively and readable magazine for everyone interested in ideas.
<br> This is a test
我该怎么做?
答案 0 :(得分:-1)
我想这会对你有帮助。
<cfscript>
str = "<br/><br /><br /> <html><br><br>test<br>test<br>";
str = REReplaceNoCase(str,"^(<.*?>|\s*)*","","All");
writedump(str);
</cfscript>
答案 1 :(得分:-1)
不确定你需要这个@nasaa的正则表达式 - 你的例子真的需要在最后一个r&gt;之后删除所有内容。这是可预测的吗?有多少种变化?你可以像somthign那样做。
<cfset mystring = right(mystring,len(mystring-find(mystring,"r>")+1))/>
可能需要+2(我总是要调整它),但你明白了。
当然,如果它不可预测那么Regex可能就是这样。无论我使用多少次,我总是对正则表达式有困难。 sytax只是毛茸茸的:))
答案 2 :(得分:-1)
这会将<br>
和<br />
删除的次数与文本开头的次数相同。它还删除了前导空格,但没有其他空格。
<cfset mystring="<br /><br>Philosophy Now is a lively and readable magazine for everyone interested in ideas.
<br> This is a test">
<cfset myreplace=ReReplaceNoCase(mystring,"^[ ]*(<br[ \/]*>[ ]*)*[ ]*","","ALL")>
<cfset mystring="<br /><br>Philosophy Now is a lively and readable magazine for everyone interested in ideas.
<Br> This is a test">
<cfset myreplace=ReReplaceNoCase(mystring,"^[ ]*(<br[ \/]*>[ ]*)*[ ]*","","ALL")>
<cfoutput><textarea rows="10" cols="50">#mystring#</textarea><br /><br />
<textarea rows="10" cols="50">#myreplace#</textarea></cfoutput>