【发布时间】:2012-08-08 13:17:21
【问题描述】:
我有以下代码:
ttt = 'hello---,,..there';
tt2 = strip(ttt);
alert(tt2);
function strip(str){
return str.replace(/[^a-zA-Z0-9 ,.-_]/g, '');
}
警报给出hello,,..there
我希望它给出hello---,,..there,因为包括连字符在内的所有字符都在替换函数中被指定为例外。
我做错了什么?
谢谢。
【问题讨论】:
标签: javascript string replace hyphen