Try this - #\b(?:[url]http://)?(www\.)?(([/url][a-z0-9_-]{2,}\.)+[a-z]{2,}(/[\w\+\-\?\&\;]*)*)\b#i
Code:
# delimiter (start of pattern)
\b word boundary
(?:http://)? optional, non-capturing "http://"
(www\.)? optional, capturing (will be $1) "www."
( start of capturing group (will be $2)
( start of sub-pattern (will be $3)
[a-z0-9_-]{2,} something that looks like a domain name
\. followed by a dot
)+ end of $3 - one or more matches
[a-z]{2,} followed by something that looks like a TLD
( start of sub-pattern (will be $4)
/ a slash
[\w\+\-\?\&\;]* followed by something that looks like a path and/or query string
)* end of $4 - zero or more matches
) end of $2 - one match only ($2 also contains $3 and $4)
\b word boundary
#i delimiter (end of pattern), case-insensitive
tested:
PHP Code:
$text = "Looking for marketers who want to work. Ready to change your life? Trevo offers one product - an all natural, vegan, kosher nutritional supplement with 174 nutraceuticals. Visit www.SoCal.trevobuilder.com for product info & to purchase. Find me on facebook at Trevo SoCal or @TrevoSoCal on twitter. Low start up, cost covers first 3 bottles or larger packages available. No registration fees. Start making money this week! Visit trevocorporate.com/coach/sjahr to register on the Presidential Elite team.";
$regexp = "#\b(?:http://)?(www\.)?([a-z0-9_-]{2,}\.[a-z]{2,}(/[\w\+\-\?\&\;]*)*)\b#i";
$hypertext = preg_replace( $regexp,'<a href="http://$1$2">$1$2</a>',$text );
print htmlentities( $hypertext );
Note that this pattern will match most (not all) valid URLs, and will not match most (not all) non-URL text. It might be a good, workable compromise for your purpose.
Edit: I changed this after posting it. Compare and make sure you're using this version.