Page 1 of 1

Help with this regex

Posted: Thu Feb 18, 2010 9:51 am
by klevis miho
I have this string:

<a href="http://prodigy.msn.com/">
<a href="http://sympatico.msn.ca">
<a href="http://web.archive.org/web/199612210104 ... SoHo/9120/">
<a href="http://web.archive.org/web/199612301933 ... 20,00.html">
<a href="http://webtrends.about.com/od/profi3/p/ ... ft-bio.htm">
<a href="http://www.alexa.com/data/details/main/MSN.com">

and $variable = 'msn.com';

I want to get just the url's which have $variable inside.

Any help would be great appreciated.

Re: Help with this regex

Posted: Thu Feb 18, 2010 1:26 pm
by AbraCadaver
Assuming that is the only format you will see:

Code: Select all

$variable = 'msn.com';
preg_match_all('#href="(http://[^\.]*\.?' . preg_quote($variable, '#') . '[^"]*)"#', $input, $matches);
print_r($matches[1]);