Reputation: 9938
I am trying to remove all html tags using this regex:
<.+>(.+)</.+>
And I replace like this:
"<b onclick=\"foo\">Foo</b> bar".replace(new RegExp("\\<.{1,}\\>(.{1,})\\</.{1,}\\>", "g"), "$1")
This works fine, however, this doesnt work:
"<b onclick=\"foo\">Foo</b> bar <b>hello</b>".replace(new RegExp("\\<.{1,}\\>(.{1,})\\</.{1,}\\>", "g"), "$1")
Since I get hello
Upvotes: 0
Views: 74
Reputation: 41838
You can do this:
result = subject.replace(/<[^>]*>/g, "");
Explanation
<
[^>]*
*
>
Upvotes: 0
Reputation: 11116
use lazy not greedy
<.+?>
along with the g
modifier
like this :
"<b onclick=\"foo\">Foo</b> bar <b>hello</b>".replace(/<.+?>/g,'');
output:
Foo bar hello
Upvotes: 1