in reply to Matching n characters with m//g

Hello medium.dave, and welcome to the Monastery!

Within a regex, the special character ^ matches the beginning of the string,1 but you want to match the position where the previous match left off. For that, you need \G, on which see “Assertions” in perlre#Regular-Expressions.

Update: 1or at the beginning of the line if the regex has an /m modifier.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Matching n characters with m//g
by medium.dave (Novice) on Feb 22, 2016 at 05:06 UTC

    It still doesn't match. I'm at a loss here. Any ideas how to advance the pos() X characters? then i could just use substr.

    my new regex:

    $m =~ /\G(.{$sz})/g;

      OK, I've managed to solve this, what I now do is use substr() and advance the position of pos(), like so:

      my $cur_pos = pos($m); print $FH substr($m, $cur_pos, $sz); pos($m) = $cur_pos + $sz;

      works great!