in reply to Perl Pattern Matching & RegEx's
#!/usr/bin/perl use warnings; use strict; use feature qw(say); my $string = 'AAAbcdAAAdcbAAAbbdAAAxAAAA'; my $delimiter = 'AAA'; my @positions; push @positions, pos($string) while $string =~ /(?=$delimiter)/g; for my $from (@positions) { for my $to (grep $_ - length $delimiter > $from, @positions) { say substr($string, $from, $to - $from) . $delimiter; } }
Update: Typo fixed. Thanks jaiieq, damn netbooks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Pattern Matching & RegEx's
by jaiieq (Novice) on Mar 07, 2013 at 14:45 UTC | |
|
Re^2: Perl Pattern Matching & RegEx's
by Dallaylaen (Chaplain) on Mar 07, 2013 at 15:34 UTC |