如何在javascript中获取数字前两个字符 [英] how to get number beteen two characters in javascript
本文介绍了如何在javascript中获取数字前两个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用正则表达式或我的字符串是({{123} * {234} +5)"的方式在javascript中获取两个字符之间的数字,并且我想要数组中{}之间的值,即123,234
感谢u
Hi,
how to get number beteen two characters in javascript using regular expression or any way my string is "({123}*{234}+5)" and i want values between {} in array i.e. 123,234
Thank u
推荐答案
尝试以下正则表达式:
Try the following regex:
\{\d+\}
我自己解决了
我的解决方案在这里
javscript
Hi,
I solved it By myself
my solution is here
javscript
var a = "";
var temp="";
function disp(str) {
if (str.match("{(.*)}")[1].indexOf("}") != -1) {
a = a + str.match("{(.*?)}")[1] + ";";
temp = str.match("{(.*)}")[0].toString().replace(str.match("{(.*)}")[1].toString().substr(0, str.match("{(.*)}")[0].toString().indexOf("}")), "");
disp(temp.substr(1));
}
else {
a = a + temp.substr(1).match("{(.*?)}")[1];
}
return a.replace("{","").replace("}","");
}
调用函数
calling of function
var result=disp('User name {1234}hf{12}djfh{2212}')
alert(result);
它显示1234; 12; 2212
谢谢
快乐的编码:)
it shows 1234;12;2212
Thank you,
happy Coding:)
这篇关于如何在javascript中获取数字前两个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文