0

I am using a regex to test if a Rich text has any content. I have got it working using the regex to determine if there is any content in-between HTML tags. However I cannot seem to then make the same regex work effectively if there is spaces entered inbetween.

I.e a regex that has the two conditions first to check is any content is between the html tags and second if any of that content has at least one non-whitespace character? Perhaps the issue lies with doing it via JS?

Any help would be great as I have spent some time and the best I have is:

new RegExp(/>[^><]+</, "g");
Mr Sorbose
  • 777
  • 4
  • 20
  • 34
  • You do not want to use regular expressions to parse HTML. Use a different approach. – Tomalak Jun 08 '17 at 09:12
  • I'm sorry to close this right-away, and with the most infamous regex+HTML question on Stack Overflow too. But the issue is the same. *"I want to parse HTML with regex and somehow it does not quite work right*". HTML is too complex for regex. Use an HTML parser, that's what they are for. – Tomalak Jun 08 '17 at 09:15
  • JavaScript in browsers gives you easy access to the most efficient and most advanced HTML parsers on the planet - modern web browsers. Parsing HTML in a browser is basically free. Traversing the DOM to find out things about the document afterwards is basically free, too. This is the approach you should use. – Tomalak Jun 08 '17 at 09:18

0 Answers0