Javascript 制表符删除

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20057233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 17:35:12  来源:igfitidea点击:

Javascript tab character removal

javascriptregexstringparsingweb

提问by user1769667

I need to remove tab characters within text inputted into particular fields of a web interface. The problem seems to be that when this happens the resulting text now contains spaces where the tabs were.

我需要删除输入到 Web 界面特定字段的文本中的制表符。问题似乎是,当发生这种情况时,结果文本现在包含制表符所在的空格。

I tried using the regex : vVal = vVal.replace(/(\s+)/, "");but using the example input 11111[tab], the value becomes 11111[space].

我尝试使用正则表达式:vVal = vVal.replace(/(\s+)/, "");但使用示例输入11111[tab],值变为11111[space].

I dont know how this could be..

我不知道这怎么可能..

回答by anubhava

\smatches any whitespace that includes space also.

\s匹配任何包含空格的空格。

For tab try \twith global switch:

对于选项卡尝试\t使用全局开关:

vVal = vVal.replace(/\t+/g, "");