[英]regex replace string with tabs only
How can use the RegEx to replace a string if ONLY it has a tab or sequence of tabs and ignore otherwise. 如果RegEx只有一个制表符或制表符序列,则如何使用RegEx替换字符串,否则忽略。
Example: 例:
str = "\\t\\t\\t\\t";
-> replace this string with nothing ie output of str = "";
->将此字符串替换为
str = "";
即输出str = "";
str = "\\t";
-> replace this string with nothing ie output of str = "";
->将此字符串替换为
str = "";
即输出str = "";
str = "\\t\\tvar a = 10";
-> ignore replacing. ->忽略替换。
Thanks! 谢谢!
使用正则表达式替换,应该是这样的:
str.replace(/^\t+$/, '');
Try this. 尝试这个。 It should work.
它应该工作。
str.replace(/^\t+$/, "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.