in reply to substitution in regular expression
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: substitution in regular expression
by aeqr (Novice) on Apr 23, 2014 at 20:06 UTC | |
by AnomalousMonk (Archbishop) on Apr 23, 2014 at 20:26 UTC | |
by AnomalousMonk (Archbishop) on Apr 23, 2014 at 20:09 UTC | |
by aeqr (Novice) on Apr 23, 2014 at 20:15 UTC | |
by Anonymous Monk on Apr 23, 2014 at 20:21 UTC | |
by aeqr (Novice) on Apr 23, 2014 at 20:28 UTC | |
|