Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing empty <p></p> with regex

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

like image 844
Alvaro Avatar asked Dec 15 '22 07:12

Alvaro


1 Answers

You should remove the quotes:

return text.replace(/(<p><\/p>)+/g, '');
like image 143
Lulylulu Avatar answered Dec 26 '22 23:12

Lulylulu