in reply to Re: regex elegance contest - validate a pw
in thread regex elegance contest - validate a pw

Well, isn't \w also locale aware?
Example: (Germany)

% perl -e 'use locale; $_=q{äöü}; print qq{Locale aware!\n} if /^\w+$/ +;'

Results in:
Locale aware!

Thus, \w is bad when you really mean /[A-Za-z0-9]/. On the other hand, using the latter character class instead of \w is usually more of a problem for most applications. The best example is, I daresay, entering my last name in some form on the web that does this: Müller ;-)

Steffen

Replies are listed 'Best First'.
Re: Re: Re: regex elegance contest - validate a pw
by leriksen (Curate) on Feb 13, 2004 at 01:11 UTC
    I think it is also Unicode aware in 5.8+ so that introduces all sorts of variation - if Unicode is supported, \w usually refers to all alphanumberics - in fact you might see \w start to die out and things like unicode properties appear

    $word = m/([\p{Letter}\p{Number}]+)/;

    I think that is correct...

    I know that in Java's regex package, \w == \A-Za-z0-9_\ only

    I got most of this info from Friedl's Mastering Regular Expressions - if you dont own it - buy it and read it from chapters 1-7 - it is truely excellent, a standout book.

    +++++++++++++++++
    #!/usr/bin/perl
    use warnings;use strict;use brain;

      leriksen says:
      ... Friedl's Mastering Regular Expressions - if you dont own it - buy it ...
      Yeah leriksen, perhaps you should take your own advice and buy a copy. That way I could have my copy back! :-)

      Cheers!