in reply to Regex to Truncate URLs Nicely

Do use URI. That said:
my $maxlen = 35; s![?].*$!!; # chop query params if any s{^(.*)(?=/[^/]/?)}{length $1 < $maxlen ? $1 : substr($1, 0, $maxlen-3 +)."..."}e;

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Regex to Truncate URLs Nicely
by Cody Pendant (Prior) on Nov 02, 2002 at 11:05 UTC
    Neat, thank you.

    One question:

    s![?].*$!!;

    Why is the query in brackets there?
    --

    ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;
      Cause it has to be escaped outside: s!\?.*$!!; The bracketed version occasionally looks less noisy. That's all.

      Makeshifts last the longest.