in reply to A regex question...

Here's another simple solution
my $s = "012345678901234567890123456789"; print $s, "\n"; $i=0; $s =~ s/(\d{5})/$1.(++$i==3 && "<BR>" or $i!=6 && "-")/ge; print $s, "\n";

Replies are listed 'Best First'.
Re: Re: A regex question...
by Jasper (Chaplain) on May 06, 2003 at 16:09 UTC
    s/\d{5}(?!$)/$& . (++$i%3?'-':'<br>')/eg

    Is probably slightly more generic that $i!=6 :)
    (edit: string of 30 digits! $i!=6 is fine)
    But I prefer:

    $s =~ s/\B/ !(++$i%15) && '<br>' || !($i%5) && '-' /eg;

    Jasper