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
精彩评论