Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

What does it mean Nested quantifiers in regex

by anakin30 (Acolyte)
on Aug 24, 2010 at 01:34 UTC ( #856832=perlquestion: print w/ replies, xml ) Need Help??
anakin30 has asked for the wisdom of the Perl Monks concerning the following question:

Hie everyone,

My perl script gave me the error below when executed

begining of the execution was ok as script was running fine with below verbose

  • 230000 ==> took 44 seconds
  • 235000 ==> took 41 seconds
  • 240000 ==> took 43 seconds
  • 245000 ==> took 42 seconds
  • Suddenly the script stop running after the last line above and generated below error

    Nested quantifiers in regex; marked by <-- HERE in m/^de.e++ <-- HERE issues@dell.com$/ at ./crestbycountry.pl line 420, <DATA> line 1063.

    Do you have any idea what we can do to rectify this one here?

    Do i have to post my perl script in here for you guys to help me?

    The script has 906 lines :)

    Thank you Guys

    Comment on What does it mean Nested quantifiers in regex
    Re: What does it mean Nested quantifiers in regex
    by jwkrahn (Monsignor) on Aug 24, 2010 at 01:46 UTC

       + in the regular expression says to match the previous character (in your case the character  e ) one or more times, but you can't have another modifier at the end of that modifier.

        A regex quantifier combination like  ++   is illegal in Perl 5.8, but is supported in 5.10 et seq. See discussion of 'possessive' quantifiers in Quantifiers section of perlre (for 5.10++ of course).

    Re: What does it mean Nested quantifiers in regex
    by toolic (Bishop) on Aug 24, 2010 at 02:02 UTC
      Do i have to post my perl script in here for you guys to help me? The script has 906 lines :)
      No, you should not post 906 lines of code. You should get into the habit of isolating your problem to as few lines as possible. In this case, a single line can reproduce the problem.

      jwkrahn has pointed out your problem, but you can sometimes get more help using diagnostics:

      use diagnostics; m/^de.e++issues@dell.com$/; __END__ Nested quantifiers in regex; marked by <-- HERE in m/^de.e++ <-- HERE issues.com$/ at C:\Perl\toolic\foo.pl line 2 (#3) (F) You can't quantify a quantifier without intervening parenthese +s. So things like ** or +* or ?* are illegal. The <-- HERE shows in the +regular expression about where the problem was discovered. Note that the minimal matching quantifiers, *?, +?, and ?? appear to be nested quantifiers, but aren't. See perlre.
    Re: What does it mean Nested quantifiers in regex
    by jethro (Monsignor) on Aug 24, 2010 at 02:19 UTC
      Another hint: If you don't want to have these '+' as quantifiers and instead want to match plus signs literally, change them to \+\+
        ... and the quotemeta operator can also help when interpolating variables that may contain special characters into regular expressions.

        So if i changed the (m/^de.e++ ) plus sign to \+\+ it can work is it?

          Yes, but it depends on what you want to parse with that regex. If you want to parse exactly the string "de.c++issues", then you need the regex de\.c\+\+issues. Note that I also escaped the '.' as that is a special char in regexes as well. (Escaping is the method of removing the specialness of special characters by putting a '\' in front of them)

          Or as salva propossed, you could write \Qde.c++issues\E, that would automatically escape all special characters between \Q and \E. This is probably the better way as you don't seem to know much abouts regexes and there are a lot more special characters

    Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (9)
    As of 2015-05-22 14:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      In my home, the TV remote control is ...









      Results (460 votes), past polls