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

How to make a html5 breakout game in JavaScript

How to set content disposition headers for express nodejs apps

Ways of iterating Object properties in JavaScript

How to evaluate a string on a regular expression rule in JavaScript

JavaScript math constants