Trim a string with all types of spaces

var a = “151 “;
a = a.replace(/^\s+|\s+$/, “”);

//a is now “151” .

Note:
\s : Matches a single white space character, including space, tab, form feed, line feed.
Equivalent to [ \f\n\r\t\v\u00A0\u2028\u2029].

\S: Matches a single character other than white space.
Equivalent to [^ \f\n\r\t\v\u00A0\u2028\u2029].

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.