Reputation: 10400
How could I get the numbers of this string: '(31.5393701, -82.46235569999999)'
I'm already trying something but this is far away from the solution :)
text.match(/\((\d+),(\d+)\)/);
Upvotes: 1
Views: 1273
Reputation: 22535
"(31.5393701, -82.46235569999999)".replace(/\(|\)/g, '').split(', ');
Upvotes: 0
Reputation: 82933
Try string.split
e.g:
var nums = text.replace(/[^0-9-,.+]/, "").split(",");
var num1 = parseFloat(nums[0]);
var num2 = parseFloat(nums[1]);
Working Example: http://jsfiddle.net/AL3e4/
Upvotes: 3
Reputation: 1043
Try something like this
text.match(/\(([\d.-]+),\s+([\d.-]+)\)/);
Upvotes: 0
Reputation: 138087
You are pretty close, but missing the sign, the decimal digits and some spaces. If you need to capture that from a string, try this:
/\(([+-]?\d+(?:\.\d+)?)\s*,\s*([+-]?\d+(?:\.\d+)?)\)/
Upvotes: 0
Reputation: 11274
How about this:
text.replace("(","").replace(")").replace(" ").split(",");
Upvotes: 0
Reputation: 1039080
var text = '(31.5393701, -82.46235569999999)';
var matches = text.replace('(', '').replace(')', '').split(',');
if (matches.length > 1) {
var lat = Number(matches[0]);
var lon = Number(matches[1]);
alert(lat + ' ' + lon);
}
Upvotes: 1