Page 1 of 1

Ignore link in certain format - regex

Posted: Tue Feb 05, 2013 1:24 pm
by pedroz
Hi regex masters!


Having this regex expression
/((http(s?):\\/\\/{1}\S+))/
it allows to fetch a link from a text string

Code: Select all

$string = 'asdsa asdsa http://www.google.com asdasd';
// link to be fetched by the regex

$pattern = '/((http(s?):\\/\\/{1}\S+))/';
preg_match($pattern, $string, $match);


However, I would like to improve it in order to igonore the following link in $string = '[abc](http://www.google.com "def")'

Code: Select all

$string = '[abc](http://www.google.com "def")';
// link to be IGNORED by the regex

$pattern = '/((http(s?):\\/\\/{1}\S+))/';
preg_match($pattern, $string, $match);

Many thanks

Re: Ignore link in certain format - regex

Posted: Tue Feb 05, 2013 9:34 pm
by Christopher
What characters cannot come before or after the string? Does the URL always have to have spaces around it?