problems with url and email regex when searching text

Posted by Grant Collins on Stack Overflow See other posts from Stack Overflow or by Grant Collins
Published on 2010-05-16T21:48:14Z Indexed on 2010/05/16 21:50 UTC
Read the original article Hit count: 255

Filed under:
|

Hi,

I'm having problems with regular expressions that I got from regexlib. I am trying to do a preg_replace() on a some text and want to replace/remove email addresses and URLs (http/https/ftp).

The code that I am have is:

$sanitiseRegex = array(
    'email' => /'^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/',
    'http' => '/^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$/',        
);

$replace = array(
    'xxxxx',
    'xxxxx'
);

$sanitisedText = preg_replace($sanitiseRegex, $replace, $text);

However I am getting the following error: Unknown modifier '/' and $sanitisedText is null.

Can anyone see the problem with what I am doing or why the regex is failing?

Thanks

© Stack Overflow or respective owner

Related posts about regex

Related posts about php