in reply to Re: Re: Checking input
in thread Checking input

It looks to me like the character class is the beginning of a range (the [\w-] bit). I know it isn't, and I know Perl has no problems with this (I just ran a test script to verify that).

But wouldn't it be a little clearer to write the character class as either [-\w] or [\w\-] ? This is really just a formatting question more than anything else.

Replies are listed 'Best First'.
Re: Re: Re: Re: Checking input
by diotalevi (Canon) on Feb 25, 2003 at 17:45 UTC

    No - your usage is buggy. Consider perl -e 'print join "\n", qr/[\w\-]/,qr/[\w-]/,""'. Don't "escape" the hyphen because that's not what happens.


    Seeking Green geeks in Minnesota

      I'm not escaping the hyphen because it is a range, I am suggesting escaping it for a clearer regex. Or re-ordering the entries within the character class.

      Usage is buggy? How so? perl -e 'print join "\n", qr/[\w\-]/,qr/[\w-]/,""' prints

      (?-xism:[\w\-]) (?-xism:[\w-])
      on my system. That explains nothing to me.

        That demonstrates that the '\' character is not escaping anything and is infact, just being added to the character class as another potential match which is completely against the spirit of the code. In fact, writing the backslash in might lead some one (like you) to think that it was escaping the next thing when in this case it escaped nothing and is itself. If the slash worked like you expected it to both lines would read like (?:-xism:[\w-]).


        Seeking Green geeks in Minnesota