-1

I have the following:

POLYGON((7.593955993652344 33.70124816894531,3.1060409545898438 24.7247314453125,8.64349365234375 22.052650451660156,14.989128112792969 26.966629028320312,7.593955993652344 33.70124816894531))

I can also have the following:

POLYGON(7.593955993652344 33.70124816894531,3.1060409545898438 24.7247314453125,8.64349365234375 22.052650451660156,14.989128112792969 26.966629028320312,7.593955993652344 33.70124816894531)

Noting the difference in parens. I only always wants the data inside the innermost set of parents so I can split on the commas.

I had something like this let coordFinder = /\(([^)]+)\)/g; but it's not getting me both cases.

John Lippson
  • 1,269
  • 5
  • 17
  • 36

2 Answers2

-1

You could do one of the following:

\([^()]*\)

Or, getting down to the digits and dots and commas,

\([.,0-9 ]*\)

UPDATE: added snippet (works as expected) => matches both versions with one or two sets of parameters

var poly2 = "POLYGON((7.593955993652344 33.70124816894531,3.1060409545898438 24.7247314453125,8.64349365234375 22.052650451660156,14.989128112792969 26.966629028320312,7.593955993652344 33.70124816894531))",
poly1 = "POLYGON(7.593955993652344 33.70124816894531,3.1060409545898438 24.7247314453125,8.64349365234375 22.052650451660156,14.989128112792969 26.966629028320312,7.593955993652344 33.70124816894531)";

console.log(poly1.match(/\([.,0-9 ]*\)/));
console.log(poly2.match(/\([.,0-9 ]*\)/));
iPirat
  • 2,197
  • 1
  • 17
  • 30
-1

let coordFinder = /.*\((.*?)\)/;

var test1 = '((abc(123,456)))';

var test2 = '(abc)';

console.log('result in test1: ' + test1.match(coordFinder)[1]);

console.log('result in test2: ' + test2.match(coordFinder)[1]);
Ruzihm
  • 19,749
  • 5
  • 36
  • 48