js正則練習問題
832 ワード
var str = "839243680";
var ary = [" "," "," "," "," "," "," "," "," "," "];
str = str.replace(/\d/g,function(){
return ary[arguments[0]];
});
console.log(str); // -->
:
if(!String.prototype.trim){
String.prototype.trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, "");
};
}
:
function myTrim(str){
if(typeof trim == "function"){
return str.trim();
}else{
return str.replace(/(^\s*)|(\s*$)/g, "");
}
}