var str = ‘haj123sdk54hask33dkhalsd879‘; /*function findNum(str){ var arr = []; var tmp = ‘‘; for(var i=0;i<str.length;i++){ if( str.charAt(i)<=‘9‘ && str.charAt(i)>=‘0‘ ){ tmp += str.charAt(i); } else{ if(tmp){ arr.push(tmp); tmp = ‘‘; } } } if(tmp){ arr.push(tmp); tmp = ‘‘; } return arr; }*/ function findNum(str){ return str.match(/\d+/g); } alert( findNum(str) ); //[123,54,33,879]
时间: 2024-10-08 04:22:20