| Special character | Matches a | Same as |
|---|---|---|
| \d | digit | [0-9] |
| \D | non-digit | [^0-9] |
| \w | alphanumeric (word) character | [a-zA-Z0-9_] |
| \W | non-word character | [^a-zA-Z0-9_] |
| \s | whitespace character (space, tab, newline...) | [ \t\n\r\f] |
| \S | non-whitespace character | [^ \t\n\r\f] |
Other special backslashed letters are:
| Special character | Meaning |
|---|---|
| \a | alarm (beep) |
| \n | newline |
| \r | carriage return |
| \t | tab |
| \f | formfeed |
| \e | escape |
#!/usr/local/bin/perl
print "Please enter date and time, as in \"08-OCT-1997 16:30\"\n";
my $entry = <STDIN>;
chop ($entry);
if ($entry =~ /\d\d-\w\w\w-\d\d\d\d \d\d:\d\d/) {
print "good!\n";
} else {
print "wrong format!\n";
}
# Note: an even better conditional would be:
# if ($entry =~ /[0-3]\d-\w\w\w-\d\d\d\d [0-2]\d:[0-5]\d/) { }