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.
In reply to Re^5: Efficient regex matching with qr//; Can I do better?
by moritz
in thread Efficient regex matching with qr//; Can I do better?
by kruppy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |