In js, this seems to work:
var x = /(?:http://)*(w{0,3}\.?\w+\.\w{2,3}[/\w]*)/gim
var p = '<a href="$1">$1</a>';

str.replace( x, p );


On Fri, Jul 17, 2009 at 7:06 PM, Kevin Mesiab <ke...@mesiablabs.com> wrote:

> Code commented w/ "don't ask" is immediately suspect.... :P
>
>
> On Fri, Jul 17, 2009 at 6:43 PM, ferodynamics <duch...@solve360.com>wrote:
>
>>
>> I go cross-eyed when it comes to reading this stuff.  I hacked some
>> code I found, catches "bit.ly" but not (for example) "ff.im"
>>
>> (Can I post code here?)
>>
>> function urls2link($text){
>>        if (strpos($text, '...')==0) { // don't ask!
>>        $pattern =
>> '\b((((H|h)(T|t)(T|t)(P|p))\://)?(www.|[a-zA-Z0-9]{1,99}.)
>> [a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}';
>>        $pattern .=
>> '(\:[0-9]{1,5})*(/(|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]
>> +?))*)($|[^\w/][<\s]|[<\s]|[^\w/]$)';
>>        $replacement = '\'<a target="_new" href="\'.((\'$4\' == \'\')?
>> \'http://$1\':\'$1\').\'"
>>                >$1</a> $16\'';
>>        return preg_replace('¦'.$pattern.'¦e', $replacement, $text); }
>>        else return $text;
>> };
>>
>> Works most of the time, but clearly has issues.  I figure somebody has
>> already solved this and wants to share ;-)
>>
>
>
>
> --
> Kevin Mesiab
> CEO, Mesiab Labs L.L.C.
> http://twitter.com/kmesiab
> http://mesiablabs.com
> http://retweet.com
>



-- 
Kevin Mesiab
CEO, Mesiab Labs L.L.C.
http://twitter.com/kmesiab
http://mesiablabs.com
http://retweet.com

Reply via email to