and it's short enough.s/^(.{1,20}).*/$1/;
Why use a regexp? What if he wants a trailing ellipsis (= 3 dots) in case the string is shortened?
The neat thing about using regexes is that it's easy to modify to make it sing and dance, once the requirements change ever so slightly.s/^(.{1,20})(.+)?/$1 . (defined $2 ? "..." : "")/e;
In reply to Re^4: how to shorten given string?
by bart
in thread how to shorten given string?
by mellin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |