去除字符串中空格的正则表达式

str.replace(/s/g, '')

/正则表达式/   这两个斜杠是JS正则表达式的规则

s   表示字符串中的空字符

g   表示全部匹配

The s (lowercase s) matches a whitespace (blank, tab  , form-feed f and newline   or  ).

On the other hand, the S+ (uppercase S) matches anything that is not matched by s, i.e., non-whitespace.

In regex, the uppercase metacharacter denotes the inverse of the lowercase counterpart, for example, w for word character and W for non-word character.

  1. The s (lowercase s) matches a whitespace (blank, tab  , form-feed f and newline   or  ). On the other hand, the S+ (uppercase S) matches anything that is not matched by s, i.e., non-whitespace. In regex, the uppercase metacharacter denotes the inverse of the lowercase counterpart, for example, w for word character and W for non-word character.
原文地址:https://www.cnblogs.com/argenbarbie/p/7810011.html