Home > Enterprise >  How do I remove a HTML tag from a string I query from an API?
How do I remove a HTML tag from a string I query from an API?

Time:08-07

I am querying an API that returns image

<p> text.. </p>.  <b> title</b>

The problem is that the string has a html tag, I want to know how can I remove this tag or failing that it works.

Thank you. :)

CodePudding user response:

You can use this tag RegExp to remove all tags form a certain string

const tagRegExp =  new RegExp('<\s*[^>]*>', 'g')


let test = "<a>Some random.... </a><p> lorem ipsum </p>";

test = test.replace(tagRegExp, '');


console.log(test)

  • Related