PDA

View Full Version : Finding a string in a string: regex question



extnewbie
18 Aug 2008, 12:30 AM
Hi,

I know this is not a extjs specific question, but I need it solved in order to go with my extjs project.

I have a long json string with the string "size: (x,y)," included where x and y are arbitrary numbers. I need a way to extract this string from the json string.
I think I should use the js match function, but I don't know how to make the regexp for this?

Thanks!

Condor
18 Aug 2008, 12:40 AM
Try:


var xy = jsonText.match(/size: \(\s?([0-9]+)\s?,\s?([0-9]+)\s?\)/);
alert(xy[1] + ',' + xy[2]);

extnewbie
18 Aug 2008, 1:33 AM
Thanks! -that works.