簡體   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正則表達式。

正則表達式:

(<\/span> )(span)

替換字符串:

$1<span>$2</span>

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