0

Possible Duplicate:
Regex to get value of URL parameter?

If you have a facebook link such as

http://www.facebook.com/photo.php?v=107084586333124

What regular expression would extract the number at the end 107084586333124

edit: I use php

Community
  • 1
  • 1
CodeCrack
  • 5,253
  • 11
  • 44
  • 72
  • 1
    In which language? Why do you want a regular expression? – johnsyweb Jan 21 '12 at 00:00
  • 2
    Or you can just split it? strUrl.split("?v=")[1] ...? – Robbietjuh Jan 21 '12 at 00:05
  • You might want to take a look at this question (http://stackoverflow.com/questions/2940508/regex-to-get-value-of-url-parameter) - it asks the exact same question. If you're doing this as a one off on the page itself, why not use something like `$_GET['v']`? – JW8 Jan 21 '12 at 01:29

3 Answers3

0

Use PHP's built-in functions to reliably pull query string variables out of a URL. You would use something like:

parse_str(parse_url($url , PHP_URL_QUERY), $v);//where $v is not set yet or an empty array
$v = @$v['v'];//will now contain the value of v or be null if not found
Walf
  • 8,535
  • 2
  • 44
  • 59
0

I'm not familiar with the PHP regex engine, but this simple regular expression should do the trick. You will find your number in the first capture group.

v=(\d+)
Francis Gagnon
  • 3,545
  • 1
  • 16
  • 25
-1

Replace the following regexes with "".

.*?\?v\=
\D*.*

The remaining data is your number.

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
  • If you insist on using a regex for this, you're better off using `preg_match()`, so you find what you want without altering any existing data. Also, it's only one op. – Walf Jan 21 '12 at 04:36
  • @Walf I posted this answer [before any language was tagged](http://stackoverflow.com/revisions/8949424/1), and I don't know any PHP. :) – Mateen Ulhaq Jan 21 '12 at 05:27