in reply to Re^4: Efficient regex matching with qr//; Can I do better?
in thread Efficient regex matching with qr//; Can I do better?
I have probably misunderstood you somehow because this solution doesn't need named captures as far as I can tell.
It only needs named captures if you want to know which one of the regexes matched.
But then I'm unable to match at the same position.
Yes, that's true. If you really need it, and only have a relatively small number of matches, you can do something along these lines:
my $re = assemble_regex(\%hash); my $old_pos = pos; while (m/\G$re/){ $pos = $old_pos; # reset match position # ... extract name of matched regex in $matched_re here ... delete $hash{$matched_re}; # re-generate regex, without the one that previously matched: $re = assemble_regex(\%hash); }
Note that it'll be rather expansive to build the regex many times, so only do this if you have a relatively low number of matches.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Efficient regex matching with qr//; Can I do better?
by kruppy (Initiate) on Jul 14, 2008 at 18:07 UTC | |
by moritz (Cardinal) on Jul 14, 2008 at 20:35 UTC | |
by kruppy (Initiate) on Jul 15, 2008 at 05:13 UTC |