Reputation: 13837
I have a solution that I could get string from HTML tags with regex as follow:
params.replace(/<[^>]*>/g, '');
Above code is when html tag found, it replace with ''. But what I want to get like array list ['ppshein', 'male', 'javascript']
if my original string is <b>ppshein</b><span>male</span><u>javascript</u>
Please let me know how to do it, thanks.
Upvotes: 0
Views: 1785
Reputation: 571
Try this. Just split and remove the empty ones.
var string="<b>ppshein</b><span>male</span><u>javascript</u>";
var x=string.split(/<[^/].*?>(.*?)<\/.*?>/g).filter(x => (x != "")));
console.log(x);
Upvotes: 0
Reputation: 17610
I used regex to remove tags and then split it then clear empty ones
var string="<b>ppshein</b><span>male</span><u>javascript</u>";
var x=string.replace(/(<([^>]+)>)/ig, '[caps]').split("[caps]").filter(x=>x!="");
console.log(x);
Upvotes: 1