-2

I'm gonna to write regex or other expression to get coordinates after '='.

My example:

var cords = https://maps.googleapis.com/maps/api/staticmap?center=50.082961,19.966860&zoom=13&size=300x300&sensor=false&markers=color:orange%7C50.082961,19.966860&client=gme-marktplaats&channel=bt_pl&signature=lPDQWiNQ2_mY8xgoVthZHLLYWac=

I want to get 50.082961,19.966860

I know that I could use slice but I think I could write it better with regex.

Simple base for this example: \=(.[0-9]) What's next?

Kevin Jantzer
  • 9,215
  • 2
  • 28
  • 52
Cloey
  • 7

1 Answers1

0

Try this center\=(\d+\.\d+,\d+\.\d+)&

var val = 'https://maps.googleapis.com/maps/api/staticmap?center=50.082961,19.966860&zoom=13&size=300x300&sensor=false&markers=color:orange%7C50.082961,19.966860&client=gme-marktplaats&channel=bt_pl&signature=lPDQWiNQ2_mY8xgoVthZHLLYWac='.match(/center\=(\d+\.\d+,\d+\.\d+)&/)[1]

console.log(val)

But as other's have commented, you likely shouldn't be using regex for this purpose

Kevin Jantzer
  • 9,215
  • 2
  • 28
  • 52