I have a string below and I want to remove the trailing
but I'm struggling. Any help?
This is a string<br>
next line<br>
So after my function, the string should be
This is a string<br>
next line
Doing this code below doesn't seem to be working. Well, it works but it doesn't clear out two trailing breaks.
mystring=mystring.replace(/<br>$/,'');
So if my string is actually:
This is a string<br>
next line<br>
<br>
then the code above just returns
This is a string<br>
next line
<br>
If you want to remove all trailing <br>
s, then use a quantifier:
/(<br>\s*)+$/
\s
matches any white space characters, so even if there is line break between continuous <br>
s, it will still match.
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With