Logically, it is (but logic is irrelevant whenever character encodings or locales are in play). According to
perl -e 'print "\n" =~ /\v/ ? "y\n" : "n\n";'
printing "y", it is. According to
Pattern.compile("\\v").matcher("\n").matches();
returning false
in java, it's not. This wouldn't confuse me at all, if there weren't this posting claiming that
Sun’s updated Pattern class for JDK7 has a marvelous new flag, UNICODE_CHARACTER_CLASS, which makes everything work right again.
But I'm using java version "1.7.0_07" and the flag exists and seems to change nothing at all. Moreover, "\n" is no newcomer to Unicode but a plain old ASCII character, so I really don't see how this difference may happen. Probably I'm doing something stupid, but I can't see it.
perldoc perlrecharclass
says that\v
matches a "vertical whitespace character". This is further explained:Specifically,
\v
matches the following characters in 5.16:You could use a character class to get the same effect as Perl's
\v
.Of course this applies to Perl; I don't know whether it applies to Java.
The Javadoc for
java.util.regex.Pattern
explicitly mentions\v
in its "list of Perl constructs not supported by this class". So it's not that\n
doesn't belong to Java's category of "vertical whitespace"; it's that Java doesn't have a category of "vertical whitespace".Edited to add: Instead,
\v
stands for the vertical tab character, U+000B. This is a traditional escape sequence; there are also a few other traditional escape sequences that aren't allowed in Java string literals but that are supported byPattern
(\a
for alert/bell,\cX
for control-characterX
). Oddly, however, the Javadoc forPattern
fails to mention that it supports\v
; so I'm not sure if it can be expected to be supported in all JDK implementations.