3

I only want to have the numbers of my URL as return. At the moment I use:

alert(document.URL);

to get the whole URL. But is there any other easy solution to get only the ID-Numbers from my URL as result? I also use jQuery and PHP in this project.

Natan Streppel
  • 5,620
  • 6
  • 33
  • 43
Yannic Hansen
  • 225
  • 3
  • 17

2 Answers2

3

var numbers = document.URL.match(/\d+/g) will return all numbers in a URL (eg for this thread) document.URL.match(/\d+/g) => ["19570840"]

megawac
  • 10,283
  • 4
  • 36
  • 61
2
alert(document.URL.match(/\d+/g));

Simple. I would put it in a fiddle, but uhh, jsFiddle doesn't have any numbers in their url, so.

Jace Cotton
  • 1,952
  • 1
  • 20
  • 36