0

I need a 1 liner RegEx to get the ID from a url. I am using this but it does not return the id. Any idea? for the following it should return 1396. The RegEx I tried are below and none of them worked.

/(?<=id=)[^&]+/`

and (?<=ID=)\w+(?=,)

http://intranet.fda.edu/sites/study/_layouts/15/listform.aspx?PageType=4&ListId=e6dc26f3-8ba7-4216-8733-a74604f14776&ID=1396&RootFolder=*

Ninja Cowgirl
  • 10,421
  • 8
  • 33
  • 41

2 Answers2

0

Use parse_url() and parse_str().

exmple get Id from youtube url

   <?php
$url = "http://www.youtube.com/watch?v=C4kxS1ksqtw&feature=relate";
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
echo $my_array_of_vars['v'];    
  // Output: C4kxS1ksqtw
?> 
0

If ID is always numeric:

/\WID=(\d+)/

This matches a non word character then ID= then captures all the following digits.

Ethan
  • 54
  • 3