in reply to Re: Checking input
in thread Checking input

He also needs to check for '-', which \w doesn't do. That first regex should be /^[\w-]+$/

----
Reinvent a rounder wheel.

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Re: Checking input
by Nkuvu (Priest) on Feb 25, 2003 at 17:37 UTC

    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.

      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.