简体   繁体   English

使用正则表达式使用html标签处理字符串

[英]Manipulating string with html tags using regex

我有字符串test1 test2 tes<span style="color:red;">t3</span> span test4 ,我想将span标签放在</span>之后的span单词周围,而又不触及现有的span标签使用javascript正则表达式。

REgex: 正则表达式:

(<\/span> )(span)

REplacement string: 替换字符串:

$1<span>$2</span>

DEMO DEMO

> 'test1 test2 tes<span style="color:red;">t3</span> span test4'.replace(/(<\/span> )(span)/g, "$1<span>$2</span>")
'test1 test2 tes<span style="color:red;">t3</span> <span>span</span> test4'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM