in reply to Regex Subexpressions
/(a(bc?)?)/g
because yours as posted doesn't match 'ab', though it does match 'ac'. Forgive me if I'm misinterpreting. I came up with what's below, but I'm not at all sure it works in the general case. You can play with it. It gives your desired output, using my regex. It saves a possible match, then fails the regex on purpose to start backtracking to get all the possible matches.
If you can generate the regexes, it would probably be easier just to generate separate regexes.use strict; use warnings; my $test = 'abc'; my @matches; $test =~ /(a(bc?)?)(??{push @matches, $^N})(?!)/; print "@matches\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex Subexpressions
by liverpole (Monsignor) on Sep 09, 2005 at 23:24 UTC |