I want to get two string from the following url, first is -43.575285
, the second is 172.762549
http://maps.apple.com/?lsp=9902&sll=-43.575285,172.762549
I wrote a regexp pattern re = /-?\d+\.\d{6}/;
which only works for the first value, is there any way the matcher can continue search for the result string and give me the second pattern occurrence?
P.S I remember ruby has the $1-$9
to reference the occurrence.
Add the g
flag to the end...
re = /-?\d+\.\d{6}/g;
This g
is for global.
var matches = str.match(re);
Note that this won't work quite like the above if you add capturing groups.
var in="http://maps.apple.com/?lsp=9902&sll=-43.575285,172.762549";
var res=in.match(-?\d+\.\d{6}/g);
Now res is an array of matches. If you want second element,
res[1]
would get it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With