If you just want to extract overlapping triplets without changing the original string:
c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'ABCDEF'; ;; my @triplets = $s =~ m{ (?= (...)) }xmsg; printf qq{'$_' } for @triplets; " 'ABC' 'BCD' 'CDE' 'DEF'
If you want to simultaneously do substitutions to change the match string so that it ends up as 'DEF' or 'EF', that's trickier (at least, it's tricky to do with a single substitution operation), but I'm assuming substitution is just an artifact of the potential approach you happened to come up with, i.e., it's an XY Problem. Please advise on this point.
Update: See Re^3: substitution in regular expression for a string-modifying s/// solution.
In reply to Re: substitution in regular expression
by AnomalousMonk
in thread substitution in regular expression
by aeqr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |