0

I am trying to get an id from a url string generated in php depending on the page you are viewing the id can appear in different places for example

site.com/view.php?id=12&person=23 

or

site.com/view.php?loc=man&id=1782&person=43

I just need to get the id section using JQuery any ideas

Cœur
  • 34,719
  • 24
  • 185
  • 251

1 Answers1

2

You can use regex to get the id from URL.

var id = url.match(/id=(\d+)/)[1]

DEMO

REGEX Explanation

  1. /: Delimiters of regex
  2. id=: Matches literal id=
  3. () : Capturing group
  4. \d+: Matches one or more numbers
Tushar
  • 82,599
  • 19
  • 151
  • 169