如何从字符串中删除尾随html中断? [英] how to remove trailing html break from string?
本文介绍了如何从字符串中删除尾随html中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面有一个字符串,我想删除尾随的
但我正在努力。有什么帮助吗?
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>
然后上面的代码只返回
This is a string<br>
next line
<br>
推荐答案
如果你想删除所有尾随的< br>
s,然后使用量词:
If you want to remove all trailing <br>
s, then use a quantifier:
/(<br>\s*)+$/
\s
匹配任何空格字符,因此即使连续< br>
之间存在换行符,它仍会匹配。
\s
matches any white space characters, so even if there is line break between continuous <br>
s, it will still match.
这篇关于如何从字符串中删除尾随html中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文