Skip to content Skip to sidebar Skip to footer

Manipulating String With Html Tags Using Regex

I have the string test1 test2 test3 span test4 and I want to put span tag surrounding the span word which position is after

Solution 1:

REgex:

(<\/span> )(span)

REplacement string:

$1<span>$2</span>

DEMO

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

Post a Comment for "Manipulating String With Html Tags Using Regex"