How to strip out html using regular expression in JavaScript

Regular expression isn't a very viable solution for manipulating html due to the complexity of html syntax in the browser it's recommended to create dom elements, appending html source code and then manipulating it using built-in dom querySelectors that has few drawbacks especially for environments without a dom take for instance nodejs

You can use regular expression replace function as;

const str = "<b>John swana</b>"

str.replace(/(<([^>]+)>)/ig, "")

// John swana

And that's it

Comments

Popular posts from this blog

What is 'this.' keyword in JavaScript

How to iterate array elements using 'for loop' in JavaScript