http://qs321.pair.com?node_id=795693


in reply to Re^5: Regexp not capturing in named subrules
in thread Regexp not capturing in named subrules

I read the idea (?<name>...){0} in the Oniguruma documentation but it was applicable to Perl too. In Perl-5.10 implementation, (?:...){0} leaves active elements like regexp routines handy in the regexp. Really, that seems to work just fine. Anyway, it's pretty clear I'm likely doing something Yves never intended when he added (?&name) support.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^7: Regexp not capturing in named subrules
by Corion (Patriarch) on Sep 16, 2009 at 18:49 UTC

    I think the way God Intended patterns to be defined for later use is

    qr/(?(DEFINE) (?<name>pattern) )/x

      Oh, hey. I didn't find that earlier because it seems to be misfiled under the (?(condition)yes-pattern|no-pattern) section but it goes on to answer my original question

      From perlre:

      /(?<NAME>(?&NAME_PAT)) (?(DEFINE) (?<NAME_PAT>....) )/x

      Note that capture buffers matched inside of recursion are not accessible after the recursion returns, so the extra layer of capturing buffers is necessary. Thus $+{NAME_PAT} would not be defined even though $+{NAME} would be.