In some code I am maintaining, I have found the expression:
$r->{DISPLAY} =~ s/\Device//s;
What surprises me is that it match开发者_如何学Goes both device and Device!
I have not found any mention of \D in the documentation, only \d.
Can someone clarify please...
\D
is the negation of \d
, i.e. it matches anything that is not a digit.
In that regex, \D
looks like a typo. It works for both d
and D
, only because it matches any character that is not a digit (0-9).
A more appropriate regex (if the intent is to match "device" or "Device"), is:
s/(d|D)evice// # one way
s/[dD]evice// # another way
The s
option is also a bit odd. From perldoc perlop
s Treat string as single line. (Make . match a newline)
And there is no such matching going on in that line.
You already have an answer, However, there's documentation in perldoc perlrecharclass about it. See the information about Backslash sequences.
It's also mentioned in perldoc perlrequick and in the regular perldoc perlretut under Using character classes. However, in those two sections, it's rather buried.
精彩评论