Perl Challenge: Fun with Character Classes

Perl Challenge: What characters do the following regex character classes include?

  [--^]
  [^-^]
  [-^]
  [^--^]
  [^-]
  [^^]

Answers tomorrow!

4 Comments

Where are my answers?!

1. dash thru caret
2. neither dash nor caret
3. dash or caret
4. opposite of 1
5. no dash
6. no caret

to check:


use 5.012; # implies strict + feature 'say'
use Data::Dumper;
my %matches;
for my $cc (qw/--^ ^-^ -^ ^--^ ^- ^^/) {
my $re = qr/[$cc]/;
my $match = '';
do {$match .= chr($_) if chr($_) =~ $re} for (32..126); # printable ascii
$matches{$cc} = $match;
}
say Dumper \%matches

Leave a comment

About morandimus

user-pic My real name is Jeremy Holland. I've been a programmer for 25 years, using primarily Perl since 2000.