Ignore link in certain format - regex

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

Ignore link in certain format - regex

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Ignore link in certain format - regex

Post by Christopher »

What characters cannot come before or after the string? Does the URL always have to have spaces around it?
(#10850)
Post Reply