Javascript to remove trailing
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 = t开发者_开发问答xtInnerHTML.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.
Try 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
加载中,请稍侯......
精彩评论