Take the 2-minute tour ×

I wanna get from a page 2 values - lat and long. The source code contains this piece of JS:

new GLatLng(53.299671, -6.267786)

Can anyone suggest me the best method/regex? Thank you a lot.

share|improve this question
regex for what? –  genesis Aug 10 '11 at 20:58
@genesis: Probably those values in brackets. –  genesis Aug 10 '11 at 21:02

2 Answers 2

up vote 0 down vote accepted
$input = "new GLatLng(53.299671, -6.267786)"; 
preg_match("~GLatLng\(([0-9\.\-]+).*?([\.\-0-9]+)\)~i", $input, $match); 

echo $match[1]." and ".$match[2];
share|improve this answer
thanks a lot and how to get those matched values? $match[1] and $match[2]? –  MarcoZemmy Aug 10 '11 at 21:06
@MarcoZemmy: exactly sandbox.phpcode.eu/g/000b9.php –  genesis Aug 10 '11 at 21:13
You saved my day! Thanks a lot :-) –  MarcoZemmy Aug 10 '11 at 21:21
If I helped you, please help me: accept my answer (click on that link if you're not sure how to do so) –  genesis Aug 11 '11 at 5:52
Měl bych se ty výrazy fakt doučit... –  MarcoZemmy Aug 11 '11 at 7:28

Something like this should work:

preg_match("/\(([\d-.]*), ([\d-.]*)\)/",$subject,$matches); 
share|improve this answer

Your Answer


