如何在JS中从这样的字符串中提取数字。字符串:“Some_text_123_text”-> 123
问问题
193 次
3 回答
5
var s = "Some_text_123_text";
var index = s.match(/\d+/);
document.writeln(index);
于 2012-11-23T10:22:20.803 回答
1
尝试这个
var string = "Some_text_123_text";
var find = string.split("_");
for(var i = 0; i < find.length ; i ++){
if(!isNaN(Number(find[i]))){
var num = find[i];
}
}
alert(num);
于 2012-11-23T10:25:57.453 回答
0
试试这个工作小提琴
var str = "Some_text_123_text";
var patt1 = /[0-9]/g;
var arr= str.match(patt1);
var myval = arr.join("");
于 2012-11-23T10:28:07.483 回答