Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Regexp not capturing in named subrules

by ikegami (Pope)
on Sep 16, 2009 at 16:57 UTC ( #795669=note: print w/ replies, xml ) Need Help??


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

(?<thing>.+) never matched "text" (backtracking occurred), so it's clearly a major bug in ruby if your code showed it did.


Comment on Re^3: Regexp not capturing in named subrules
Select or Download Code
Re^4: Regexp not capturing in named subrules (first)
by tye (Cardinal) on Sep 16, 2009 at 17:20 UTC

    For clarity, the regex expands to the equivalent of:

    re = %r{ (?: (?<thing>.+) ){0} (?<thing>.+) }

    So, yes, (?<thing>.+) did match. It is just that the first instance didn't match. In Perl, %+ only records the captures of the first instance.

    - tye        

Re^4: Regexp not capturing in named subrules
by diotalevi (Canon) on Sep 16, 2009 at 17:25 UTC

    No, you misread. \g<thing> in Ruby-1.9's oniguruma works like (?&thing) in perl 5.10. It's a subroutine call. The grammar section (?: ... ){0} creates the subroutines and I just call an entry point later.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      The grammar section (?: ... ){0} creates the subroutines...
      I'm really confused. Did you invent that construct yourself (which looks broken to me) or is it something special-cased in recent grammars (away from its pointless purpose) and recommended in some document I haven't read yet?

      Because if I was writing a regex engine, I'd actually turn {0} into a fatal error, with the invoker needing a clue-bat.

      -- Randal L. Schwartz, Perl hacker

      The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

        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.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://795669]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-07-14 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls