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
  • 37,241
  • 25
  • 195
  • 267

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
  • 85,780
  • 21
  • 159
  • 179