Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys,
Quick question: a..z is the lowercase alphabet and 0..9 is the number system, but what can I use for every character, like !@#$%^&*()?

Replies are listed 'Best First'.
Re: Char range
by fglock (Vicar) on Jun 29, 2003 at 00:53 UTC

    You can use the [:punct:] character class (see perlre)

    perl -e '  for(0..255){ print chr($_) if chr($_)=~/[[:punct:]]/; } '

    output:

    !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
Re: Char range
by The Mad Hatter (Priest) on Jun 29, 2003 at 00:16 UTC
    Well, in a regex it would be something the character class [^a-zA-Z0-9\s]. For doing loops, you'll probably just have to create a list, something like qw/! @  #  $  % ^ & * ( ) ?/.
Re: Char range
by tcf22 (Priest) on Jun 29, 2003 at 06:25 UTC
    Looks like you could be writing a script for password validation. Don't know if this will help, but I recently used this for password validation(1 letter, 1 number, 1 symbol(!@#$%^&*()?).
    if(($new_password !~ /\d/) || ($new_password !~ /[a-zA-Z]/) || ($new_password !~ /\W/) || (length($new_password) < 6)){ ...BAD PASSWORD... {
Re: Char range
by Anonymous Monk on Jun 29, 2003 at 16:10 UTC
    if you mean "every possible value in the 8 bit ASCII set" then you want [\x00-\xff].

    if you mean "every non-alphanumeric, non-whitespace char (and "_")" then you want \W.

    But you probably mean "every char i care about" in which case i suggest you sit down and just decide what you want.

    update (broquaint): added formatting

Re: Char range
by Not_a_Number (Prior) on Jun 29, 2003 at 19:54 UTC
    ...what can I use for every character?

    /.+/

    perldoc perlre:

       . Match any character (except newline)

    hth, dave