in reply to Re: Regex - Char Class Question
in thread Regex - Char Class Question

See perlop. If you're going to put a ] or - character into your character class then it has to be either escaped or be placed at the front after the optional ^,

Replies are listed 'Best First'.
Re: Re: Re: Regex - Char Class Question
by sauoq (Abbot) on Dec 10, 2003 at 19:33 UTC
    See perlop.

    Actually, see perlre.

    If you're going to put a ] or - character into your character class then it has to be either escaped or be placed at the front after the optional ^,

    Or placed at the end immediately before the closing square bracket.

    The relevant passage from perlre:

    If you want either "-" or "]" itself to be a member of a class, put it at the start of the list (possibly after a "^"), or escape it with a backslash. "-" is also taken literally when it is at the end of the list, just before the closing "]".

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Re: Regex - Char Class Question
by sth (Priest) on Dec 10, 2003 at 18:43 UTC

    I knew I could escape the '-', I just wanted figure out what I was missing, was driving me nuts.

    Thanks for the reply!