admin管理员组文章数量:1302930
how to split the numeric values from alphanumeric string value using java script?
for example,
x = "example123";
from this i need 123
thanks.
how to split the numeric values from alphanumeric string value using java script?
for example,
x = "example123";
from this i need 123
thanks.
Share Improve this question asked Jun 16, 2010 at 9:31 VinothPHPVinothPHP 8212 gold badges10 silver badges22 bronze badges1 Answer
Reset to default 7Easiest way would be:
var str = "example123";
str = str.replace(/[^0-9]+/ig,"");
alert(str); //Outputs '123'
However, for string "example123example123" - it will return "123123". If you need to get both numbers as separate values, then it would be a little more plex:
var str="Hello 123 world 321! 111";
var patt=/[0-9]+/g;
while (true) {
var result=patt.exec(str);
if (result == null) break;
document.write("Returned value: " + result+"<br/>");
}
//Outputs:
//Returned value: 123
//Returned value: 321
//Returned value: 111
本文标签: how to split the numeric values from alphanumeric string value using javascriptStack Overflow
版权声明:本文标题:how to split the numeric values from alphanumeric string value using javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741732613a2394917.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论