I am looking for a way within PHP to pull the second link http://secure.hello.com
out of the following string via regex.
http://hello.com/http://secure.hello.com
The string may or may not contain https
in either of the spots.
I am looking for a way within PHP to pull the second link http://secure.hello.com
out of the following string via regex.
http://hello.com/http://secure.hello.com
The string may or may not contain https
in either of the spots.
Try this regular expression:
://\S*/(\w+://\S*)
It searches for the first ://
then searches for a slash followed by some word characters, then ://
, then anything apart from spaces. The text you want is in the first capturing group.
In a PHP string literal it can be written as:
'#://\S*/(\w+://\S*)#'
See it working online: ideone
If you want to restrict to http or https, change the \w+
to https?
.