in reply to List-to-Range generation
Here's one way to fix it:
The negative look-behind at the beginning and the negative look-ahead near the end prevent the regex from matching only part of a number, like the second 1 in 11 or the 3 in 30.sub num2range { local $_ = join ',' => @_; s/(?<!\d)(\d+)(?:,((??{$++1}))(?!\d))+/$1-$+/g; return $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: List-to-Range generation
by japhy (Canon) on Jun 12, 2001 at 04:06 UTC | |
|
Re^2: List-to-Range generation
by rmocster (Novice) on Jul 21, 2016 at 21:52 UTC |