in reply to Re^2: Quantifier follows nothing error in Regexp::Grammars (quantifier "?")
in thread Quantifier follows nothing error in Regexp::Grammars

Minor comment: the hyphen should be the first character in the character class:

Why do you think so, what are the reasons for this habit/style?

I vaguely recall maybe that I read this advice before, but it didn't stick :) (not memorable)

  • Comment on Re^3: Quantifier follows nothing error in Regexp::Grammars (hyphen charclass)

Replies are listed 'Best First'.
Re^4: Quantifier follows nothing error in Regexp::Grammars (hyphen charclass)
by hdb (Monsignor) on Oct 09, 2013 at 08:42 UTC

    If you write /[:-&]/, you get Invalid [] range ":-&" in regex; marked by <-- HERE in m/[:-& <-- HERE ]/ because ':' comes later in the ASCII table than '&'.

    If you write /[&-:]/, it matches each of &'()*+,-./0123456789:, the full range in the ASCII table between ':' and '&'.

    If you write /[-&:]/, it matches only one of -&: as the hyphen is not interpreted as a range operator.

    Of course, you can escape it with a backslash as well, which is the case in the post above but I had not seen when I first looked at it.

      Of course, you can escape it with a backslash as well, which is the case in the post above but I had not seen when I first looked at it.

      Oh, I see :) I thought you might have had some other reasoning ... that maybe excluded backslash ... :) hi guy, its me I am

Re^4: Quantifier follows nothing error in Regexp::Grammars (hyphen charclass)
by Happy-the-monk (Canon) on Oct 09, 2013 at 08:44 UTC

    what are the reasons for this habit/style?

    in a character class, the hyphen is a range operator as in [0-9A-Za-z] or [A-z]-foolery.

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)