Jeff,
A space inside a character class (such as the one he has) matches just that - a space. Whitespace is matched normally inside regexs unless a certain option is turned on (which I forget right now). In other words,
- $line =~ /This is a test./;
will correctly match "This is a test." but not "Thisisatest."
- C:\Users\Ganon11>perl
-
while (1) {
-
chomp(my $line = <STDIN>);
-
if ($line =~ /This is a test./) {
-
print "Successful match.\n";
-
} else {
-
print "No match.\n";
-
}
-
}
-
^Z
-
This is a test.
-
Successful match.
-
Thisisatest.
-
No match.
-
^C
Similarly,
will match "Dogs ", "Cats ", but not "Mouse".
- C:\Users\Ganon11>perl
-
while (1) {
-
chomp(my $line = <STDIN>);
-
if ($line =~ /(\w+)[ \t]/) {
-
print "Successful match.\n";
-
} else {
-
print "No match.\n";
-
}
-
}
-
^Z
-
Dogs
-
No match.
-
Dogs and
-
Successful match.
-
Cats
-
Successful match.
-
There was a tab in the previous line
-
Successful match.
-
Mousenospace
-
No match.
-
^C
The special character \s is special only because it matches any kind of whitespace - therefore, I believe \s is equivalent to [ \t\n].