in reply to Delimited Backtracking with Regex
Take advantage of regexp backtracking to find all the possibilities.
my $str = "TXXXABCDGXXXCCCDTGYYYCCCYYYCC"; local our @matches; $str =~ m/ (XXX.*YYY) # Search and capture (?{ push @matches, $1 }) # Save result (?!) # Try again /x; print "$_\n" foreach @matches;
outputs
XXXABCDGXXXCCCDTGYYYCCCYYY XXXABCDGXXXCCCDTGYYY XXXCCCDTGYYYCCCYYY XXXCCCDTGYYY
Update: Followed japhy's suggestion
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Delimited Backtracking with Regex
by japhy (Canon) on Apr 21, 2006 at 02:14 UTC | |
Re^2: Delimited Backtracking with Regex
by ikegami (Patriarch) on Apr 21, 2006 at 02:26 UTC | |
by blokhead (Monsignor) on Apr 21, 2006 at 03:07 UTC | |
Re^2: Delimited Backtracking with Regex
by neversaint (Deacon) on Apr 21, 2006 at 02:24 UTC |
In Section
Seekers of Perl Wisdom