0

I would like to convert a html code into text by using regexr. I am a beginner and I don't really know how to do it with split() and replace()...

For example:

const = myArtcle {
article: <p class="some-style">Some text with 094blabla.</p>
<img src="#" /><p class="style"> etc...</p>.
}

I tried this:

const textArticle = myArticle.article;

const deleteHTML = new RegExp(/\<(.*?)\>/);

const parsingText = () => {
    textArticle.split(deleteHTML, '');
    return (textArticle);
}

And I would like to have a parahraph:

Some text with 094blabla.  etc...

instead of the html tags with the paragraph (so I want to remove all the html tags and only get the paragraph)

I would like to do it with RegExr and function JavaScript only.

  • 1
    Can you please edit your question adding a real example of `html` input that should be parsed with the real desired output? – Calvin Nunes Jul 30 '18 at 16:57
  • Related: https://stackoverflow.com/a/1732454/4283581 – Grant Miller Jul 30 '18 at 19:36
  • [`String.prototype.split()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) doesn't take an empty string for a second parameter. Also, you can probably drop that capturing group. – Joseph Marikle Jul 30 '18 at 19:50
  • That doesn't look like valid syntax. You need a variable identifer after `const`. Also, after `article` there should probably be a string indicator like `'` or `"`, but there isn't any... – CertainPerformance Jul 31 '18 at 05:32

0 Answers0