如何删除div标签中没有class,id和style属性的属性需要使用coldfusion删除?

时间:2017-11-14 13:25:46

标签: regex coldfusion

我有这样的属性。 例如:

<div class="issue-document" id="assr_0335-5985_1991_num_76_1_1619" itemprop="hasPart" itemscope="" itemtype="https://facebook.com>

<cfset mystring = 'This is some text. It is true that <div class="issue-document" id="assr_0335-5985_1991_num_76_1_1619" itemprop="hasPart" itemscope="" itemtype="https://facebook.com">Harry Potter</div> is a good, but is better'>
<cfset MyReplace = ReReplaceNoCase(mystring,"<div [^>]*>","","ALL")>

<cfoutput><pre>Original string: #mystring# 


Without link: #myreplace#</pre></cfoutput>

我只需删除itemscope和itemprop,就像id,class,style这样的其余属性我不想在正则表达式中使用coldfusion删除。任何人都可以帮助找到解决方案。

1 个答案:

答案 0 :(得分:0)

<cfset myReplace = reReplaceNoCase(mystring, '\b(itemscope|itemprop)="[^"]*"', "", "all")) />

https://trycf.com/gist/8d84d7d355f7c54e5533eeed22d097ba/acf2016?theme=monokai