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

JavaScript introduction to variables

how to dump a postgresql database using from the terminal

How to set content disposition headers for express nodejs apps

Solutions to blocked URLs on Facebook

How to get user's ip address in JavaScript