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
    That's mine, from Snippets. But you can feel free to use it!

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      In my head, almost all my regex's are from japhy.

      moment of silence...