admin管理员组文章数量:1356067
I am getting a string which is nothing but innerHTML, and so it has instances of
. I need to trim the string such that the trailing
alone are removed.
Tried this:
var text;
text = txtInnerHTML.replace(/(
)*/g,"");
This removes all instances of
which is not desired.. Only the trailing
instances may be which may be zero or more need to be removed.
I am getting a string which is nothing but innerHTML, and so it has instances of
. I need to trim the string such that the trailing
alone are removed.
Tried this:
var text;
text = txtInnerHTML.replace(/(
)*/g,"");
This removes all instances of
which is not desired.. Only the trailing
instances may be which may be zero or more need to be removed.
4 Answers
Reset to default 3Try txtInnerHTML.replace(/( )+$/g,"");
Use the end of string anchor
text.replace(/( )+$/, '');
I remembered which one is which by the mnemonic *carrots are more important than money(. Weird, but it worked for me when I was learning. It basically says ^
is the start anchor and $
is the end anchor. Probably doesn't make much sense out of localizations that use $ for money value.
text = txtInnerHTML.replace(/( )*$/,"")
txtInnerHTML.replace(/( |\s)$/,"");
$
Matches the ending position of the string or the position just before a string-ending $newline. In line-based tools, it matches the ending position of any line.
wikipedia
Don't forget about simple space " ". Regular expression above removes or " " in the end of string
本文标签: Javascript to remove trailing ampnbspStack Overflow
版权声明:本文标题:Javascript to remove trailing   - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744034178a2579459.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论