似乎无法 trim 所有前导空格 - JavaScript 或 jQuery
Can't seem to trim all leading whitespace - JavaScript or jQuery
我正在尝试使用以下代码 trim 来自文本区域输入框的所有前导空格:
replaceString = replaceString.replace(/^\s+|^\t+|\t+|\s+$/g, "");
当我这样做时,我从
.map_image #map_link_0 { width: 40px; height: 42px; top: 11px; left: 11px; }
.map_image #map_link_1 { width: 47px; height: 42px; top: 62px; left: 19px; }
至
.map_image #map_link_0 { width: 40px; height: 42px; top: 11px; left: 11px; }
.map_image #map_link_1 { width: 47px; height: 42px; top: 62px; left: 19px; }
我做错了什么?
表达式默认不考虑多行,因此 ^
仅匹配您输入的开头。您可以通过添加多行 /m
标志(总共 /gm
)来解决此问题。
^
Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character.
$
Matches end of input. If the multiline flag is set to true, also matches immediately before a line break character.
我正在尝试使用以下代码 trim 来自文本区域输入框的所有前导空格:
replaceString = replaceString.replace(/^\s+|^\t+|\t+|\s+$/g, "");
当我这样做时,我从
.map_image #map_link_0 { width: 40px; height: 42px; top: 11px; left: 11px; }
.map_image #map_link_1 { width: 47px; height: 42px; top: 62px; left: 19px; }
至
.map_image #map_link_0 { width: 40px; height: 42px; top: 11px; left: 11px; }
.map_image #map_link_1 { width: 47px; height: 42px; top: 62px; left: 19px; }
我做错了什么?
表达式默认不考虑多行,因此 ^
仅匹配您输入的开头。您可以通过添加多行 /m
标志(总共 /gm
)来解决此问题。
^
Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character.
$
Matches end of input. If the multiline flag is set to true, also matches immediately before a line break character.