in my website i have three regular expressions (one is disabled and you'll understand why...) to substitute what users posts:
1° Replace email with linked ones:
$string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<a href=\"mailto:$1\">$1</a>",$string);
2° Replace Youtube link with embed video:
$pattern = '/http:\/\/www\.youtube\.com\/watch\?(.*?)v=([a-zA-Z0-9_\-]+)(\S*)/i';
$replace = '<iframe title="YouTube" class="youtube" type="text/html" width="320" height="240" src="http://www.youtube.com/embed/$2" frameborder="0" allowFullScreen></iframe>';
$string = preg_replace($pattern, $replace, $string);
3° Replace links with linked ones (these are disabled!):
/*** make sure there is an http:// on all URLs ***/
$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
/*** make all URLs links ***/
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>",$string);
My problem is that, obviously, the third one substitute youtube links after they are replaced by previous regexp (switching sequence, break youtube videos)
How to enable third regexp to substitute URLs ignoring youtube pattern? Thank you ;-)