Reputation: 23
I want to remove the tags and make the selected text between the tags to upper, don't know how?
var pattern = 'We are <orgcase>liViNg</orgcase> in a <upcase>yellow submarine</upcase>.'
var myRegexp = /<upcase>(.*?)<\/upcase>/g;
var match = "$1";
var str = pattern.replace(myRegexp, match.toUpperCase());
console.log(str);
Upvotes: 0
Views: 59
Reputation: 34556
You need to use replace
with a callback so the matched values can be fed to it and handled.
var str = 'We are <orgcase>liViNg</orgcase> in a <upcase>yellow submarine</upcase>.'
var str = str.replace(/<upcase>(.*?)<\/upcase>/g, function($0) { return $0.toUpperCase(); });
alert(str);
As for then removing the tags:
str = str.replace(/<\/?[^>]+>/g, '');
Upvotes: 2