in reply to Question on s///eg
I've forgotten where this came from, but it could be helpful.
$n="1,2,3,4,9,10,11,12,14,16,17,18"; $n =~ s{ (?<!\d) (\d+) (?: , ( (??{ 1 + $+ }) ) )+ }{$1-$+}gx; print "$n\n"; $ perl cool_regex.pl 1-4,9-12,14,16-18
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Question on s///eg
by japhy (Canon) on Feb 27, 2002 at 23:01 UTC | |
by zengargoyle (Deacon) on Feb 27, 2002 at 23:18 UTC |