0

How can I modify this string:

"SRID=4326;POINT (-21.93038619999993 64.1444948)" 

so it will return

"-21.93038619999993 64.1444948" 

(and then I can split that)?

The numbers in the string can be different.

I've tried using .replace & split, but I couldn't get it to work properly. How can I make this happen using Javascript?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Reyni
  • 69
  • 7

4 Answers4

1

You can try with match and regex:

"SRID=4326;POINT (-21.93038619999993 64.1444948)".match(/\(([^)]+)\)/)[1]

// "-21.93038619999993 64.1444948"
hsz
  • 148,279
  • 62
  • 259
  • 315
1

I am not good using REGEXP but this could be a solution with pure split.

Hope it helps :>

var str = "SRID=4326;POINT (-21.93038619999993 64.1444948)" ;
var newStr = str.split('(')[1].split(')')[0];
console.log(newStr)
Gerardo BLANCO
  • 5,590
  • 1
  • 16
  • 35
0
var new_string = string.replace("SRID=4326;POINT (", "");
Fazie
  • 67
  • 6
0

You can use a regular expression. The first number is put in first, the second number is put in second.

const INPUT = "SRID=4326;POINT (-21.93038619999993 64.1444948)";
const REGEX = /SRID=\d+;POINT \((.+) (.+)\)/

const [_, first, second] = INPUT.match(REGEX);

console.log(first);
console.log(second);
Jeroen
  • 15,257
  • 12
  • 59
  • 102