4

I'm trying to get rid of empty paragraphs using replace with a regex, but not having luck.

return text.replace('/(<p><\/p>)+/g', '');

I've tested the regex /(<p><\/p>)+/g in regex101 and it seems to be ok. What am I doing wrong?

Reproduction online

Alvaro
  • 40,778
  • 30
  • 164
  • 336

2 Answers2

7

You should remove the quotes:

return text.replace(/(<p><\/p>)+/g, '');
Lulylulu
  • 1,254
  • 8
  • 17
5

Almost there ... but a regex in JS isn't a string

Your's

return text.replace('/(<p><\/p>)+/g', '');

Try this

return text.replace(/(<p><\/p>)+/g, '');
Wainage
  • 4,892
  • 3
  • 12
  • 22