I want to replace the characters <
and >
from the text.
I have a regex as below:
(<span[^>]+class\s*=\s*("|')subValue\2[^>]*>)[^<]*(<\/span>)|(<br(\/*)>)
It is to target <br/>
, <br>
, <span class="subValue">......</span>
. And I want to replace the <
and >
with <
and >
.
When I wrapped it with a big bracket, it doesn't select out the <
and >
that from the <span>
or <br>
. Instead, it selected all <
and >
.
(<|>)(?!(<span[^>]+class\s*=\s*("|')subValue\2[^>]*>)[^<]*(<\/span>)|(<br(\/*)>))
What is wrong with the regex?
I have created a sample here.
Code snippet sample.
var str = '-<br><span class="subValue">Value Here<br/>';
regex = new RegExp('(?<=span|br)(<|>)|(<|>)(?=span|br)|(?<="subValue"|\'subValue\')>|<(?=\/)|(?<=br\/)[\s]*>', 'gi');
//str = str.match(regex);
str = str.replace(regex, 'Testing');
$('#lol').html(str);
<div id="result" style="border:1px solid red;"></div>
`, instead, it selected out all `<` and `>` from the overall input. – Chin Dec 03 '15 at 06:50