开发者

Replacing special chars from the output

searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == - 1) return;
    return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
}

... returns browser version, in m开发者_如何学Pythony case, its "3.6". Since I'm going to use this as a class name, I want to remove any special chars including the "." in it, or replace it with an "-" or "_" and lowercase everything. Want to sanitize is basically.

Thanks!


"3.6".replace(/\W/g,"_")
3_6

\W - any character except A-Za-z0-9_

UPDATE:

"Firefox/3.6".replace(/\W/g,"_").toLowerCase()
firefox_3_6
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜