I'm having trouble retrieving a URL parameter from a string using regular expressions:
An example string could be
some text and http://google.com/?something=this&tag=yahoo.com and more text
, and I would like to be able to find yahoo.com
from this.
The caveat is that I need to ensure that the string begins with http://google.com
, and not just search for &tag=(.*)
preg_match("/google\.com\/.*&tag=(.*) $/", $subject, $matches)
i'm hoping this matches anything with google.com
followed by anything, followed by &tag=
followed by a space. Ultimately the goal is to parse out all of the tag=
values from google.com
URLs.
Is there a better way to accomplish this?
Update:
so I have this new regex: /google\.com\/.*(tag=.*)/
but i'm not sure how to get it to end on a space after the URL