Don't ask to ask, just ask | |
PerlMonks |
Re: Plug for an alternate regex engineby hv (Prior) |
on Feb 21, 2006 at 10:46 UTC ( [id://531654]=note: print w/replies, xml ) | Need Help?? |
It is certainly possible to write a function that accepts information about the values you want to set for the variables, that returns a regexp to set them up in that way. As you supposed, the parens are counted at regexp compile time, so it is not possible to embed all the logic in a regexp without fixing the paren count in advance. $^N will be the first You may need to allow for some captures being unset, as in "ac" =~ /(a)?(b)?(c)?/. For the simple case where the nesting is natural, most efficient would be to forget the lookaheads and just construct a nesting of dots and parens, along with a simple negative lookahead for unset parens ((?!))?. I think something like the below would do it, but I have not tested it exhaustively:
Extending this to add lookaheads for captures that are not naturally nested is left as an exercise for the reader. :) With respect to your title, note that it is possible to plug in an alternate regexp engine - this is how use re 'debug' is implemented - but I'm not aware that anyone has ever taken advantage of this, nor do I imagine there is any documentation of how you might do so. Hugo
In Section
Meditations
|
|