in reply to Re: Short URL?
in thread Short URL?

I think bobafifi wanted the first 35 characters, the elipsis, and the last 15 characters if the URL was over 53 characters long.

Update The updated regex works unless the URL is exactly 53 characters long. In that case I believe bobafifi wants the URL to stay the same (although I could be wrong). Here is one that (as far as I can tell) works for any length...

$url =~ s/^(.{35})(?=.{19}).+(.{15})$/$1...$2/;

Replies are listed 'Best First'.
Re: Re: Re: Short URL?
by bart (Canon) on Apr 06, 2003 at 10:46 UTC
    The updated regex works unless the URL is exactly 53 characters long. In that case I believe bobafifi wants the URL to stay the same
    In that case, the ".{3,}" in caedes' code should become ".{4,}". Indeed, I see no reason to replace the correct string of 3 characters, by 3 dots. The code would become:
    $url =~ s/^(.{35}).{4,}(.{15})$/$1...$2/;
    I would be tempted to throw in a "?" to reduce the greediness of the middle subppatern, but it wouldn't help one bit, here.
Re: Re: Re: Short URL?
by caedes (Pilgrim) on Apr 06, 2003 at 02:18 UTC
    Yeah, I'll see about fixing that up.

    -caedes