js regularly deletes the span tag and the content inside the tag

Such as the title: The data returned by the background is a string with p tags and span tags. Originally, the v-html reference is over, but there is a strange need to delete the span tag and the content inside. It took a long time to finally realize it. up.

var temp="<p dw='6e290ab04f4e4e32bf5f2ed8dc5a1b04'>从发达国家建设工程的发展规律来看,<span      
  class ='hd'>Caf律基n;y设a础建设c能看tou家o的t工规从(i 施展程的来n达“i发国续p 持发cCna力 
  </span>基础设施的“持续能力(Capacity of Continuance)”建设和“可持续的运营、维护基础设施(Sustainable operation&amp;maintenance)”是城市化后期的国家所面临的共同问题。<span  class 
  ='hd'>从n家np发国持 力y设 看C“(no础施fa工达规的at展t来续;caucC设基律i的发建程能oi</span>从 
 国内情况来看,<span  class ='hd'>tp设u律o发展的施naa(t看持“ao从达;i家ync发i力工fc 建程基规续 
 C的nC 国能设础来</span>一方面,<span  class ='hd'>c基础的Cf力C达c 工展i能no程的t从aoan;n建(a家规u“来 i看t律国设y发发设持p续施</span>目前大型建设项目实施过程中出现“伪可持续发展”的倾向和 
 后果;另一方面,<span  class ='hd'>国础tio发n工C展的“规 a设i发设程(从施持cC续 o基nnyfaua能c 
 的来建达tp力看律家;</span>随着城市化进程的逐步深入,<span  class ='hd'>从na工 发家能Ccinp 看 
 施国的续oCa设(ut展“设律建达基发ciy程来o力规;t持的fa础n</span>我国的基础设施(包括投入使用和未 
 投入使用的)必然也面临发达国家目前的问题。<span  class ='hd'>续的C发c 设建从u基y力i达“律家onn 
 工iac国能础f来程(;Ct看 n持ao施发t规p展设的a</span></p >"

//去掉span标签里面的所有内容
var result=temp.replace(/<span\b[^<]*(?:(?!<\/span>)<[^<]*)*<\/span>/gi,"")

console.log(result)

//得到的结果
<p dw="6e290ab04f4e4e32bf5f2ed8dc5a1b04">从发达国家建设工程的发展规律来看,基础设施的“持续能力(Capacity of Continuance)”建设和“可持续的运营、维护基础设施(Sustainable operation&amp;maintenance)”是城市化后期的国家所面临的共同问题。从国内情况来看,一方面,目前大型建设项目实施过程中出现“伪可持续发展”的倾向和后果;另一方面,随着城市化进程的逐步深入,我国的基础设施(包括投入使用和未投入使用的)必然也面临发达国家目前的问题</p >

If you want to modify other tags, you can directly replace the span in the regular expression with other tags in the same way.

Guess you like

Origin blog.csdn.net/qq_42174597/article/details/125937147