I'm trying to use regex to replace all <br /> tags and character from the data of ckeditor and validate if it's empty will alert an error. But somehow if i press enter multiple time in ckeditor, it will generate multiple line with content like this:
<br />
<br /> <br /> <br /> <br /> <br />
I wrote this code and try to console out the result but it print out something like a blank string with break lines, not <empty string>. Is there any wrong in my code?
<empty string>
var str = "<br /> "+ "<br /> "+ "<br /> "+ "<br /> "+ "<br /> "+ " "; str = str.replace(/( )*/gm,''); str = str.replace(/^s*$/gm,''); str = str.replace(/<brs*/?>/gm, ""); console.log(str);
Finnally, i found the resolution. I also have to remove in string, the code will run properly.
str = str.replace(/ /gm,'');
2.1m questions
2.1m answers
60 comments
57.0k users