Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Try the following regex:
\{\d+\}
 
Share this answer
 
Comments
Nilesh Patil Kolhapur 22-Jul-12 6:38am    
not working it returns null
Mehdi Gholam 22-Jul-12 6:44am    
Show the code you are using.
Nilesh Patil Kolhapur 22-Jul-12 6:45am    
function disp() {
var a = "Formula Expr {1234}*{2212}+2";
alert(a.match("\{\d+\}"));
}
i want 1234 and 2212 in arrays
note-this string is not fixed its dynamic
Mehdi Gholam 22-Jul-12 6:59am    
You have to deliminate -> "\\{\\d+\\}"
Nilesh Patil Kolhapur 22-Jul-12 7:11am    
sorry sir but its not full fill my requirement it returns {1234} and i want two values i.e 1234 and 2212
Hi,
I solved it By myself
my solution is here

javscript
C#
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

JavaScript
var result=disp('User name {1234}hf{12}djfh{2212}')
alert(result);


it shows 1234;12;2212

Thank you,
happy Coding:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900