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
  • 155,085
  • 27
  • 166
  • 222
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
  • 143,040
  • 58
  • 252
  • 308
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,426
  • 1
  • 17
  • 34
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
  • 13,308
  • 11
  • 53
  • 98