in reply to Why does \w include numbers and underscore?

Once I patch Perl to make it Level 1 TR18-compliant, then you'll be able to write things like if ($str =~ /^[\w-\d]+$/) { ... }
_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re^2: Why does \w include numbers and underscore?
by tye (Sage) on Apr 22, 2004 at 02:58 UTC

    Perl has supported [^\W\d] forever. One of my favorites is [^\S\n] (any whitespace character but newline).

    (update) I wasn't trying to argue against nor diminish your proposed patch. I just wanted to mention this solution to this problem which didn't appear to be covered in the thread yet.

    - tye        

      Yeah, but those are simple cases. I'm looking for scalability.
      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
Re: Re: Why does \w include numbers and underscore?
by halley (Prior) on Apr 22, 2004 at 13:41 UTC
    To see if I understand, qr/[a-z]/ is to be seen as class consisting of a range, but qr/[\w-\d]/ is to be seen as a class composed by the difference between sets?

    Would qr/[\d-89]/ find only octal digits or would it find the 9 too?

    --
    [ e d @ h a l l e y . c c ]

      If I understand TR18 correctly, it would match only octal digits. All the examples in TR18 show additional brackets or give whitespace to help make things clear.

      Union binds tighter than intersection, which binds tighter than subtraction, so [\d-89] is the same as [\d-[89]].

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;