[twitter-dev] Re: How to pattern-match these crazy shortened URLs?

2009-07-17 Thread Kevin Mesiab
In js, this seems to work:
var x = /(?:http://)*(w{0,3}\.?\w+\.\w{2,3}[/\w]*)/gim
var p = '$1';

str.replace( x, p );


On Fri, Jul 17, 2009 at 7:06 PM, Kevin Mesiab  wrote:

> Code commented w/ "don't ask" is immediately suspect :P
>
>
> On Fri, Jul 17, 2009 at 6:43 PM, ferodynamics 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 =
>> '\bH|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 = '\'http://$1\':\'$1\').\'"
>>>$1 $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


[twitter-dev] Re: How to pattern-match these crazy shortened URLs?

2009-07-17 Thread Kevin Mesiab
Code commented w/ "don't ask" is immediately suspect :P

On Fri, Jul 17, 2009 at 6:43 PM, ferodynamics  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 =
> '\bH|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 = '\'http://$1\':\'$1\').\'"
>>$1 $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