是“\ n”吗?垂直的空白,即应该是“\v”。匹配吗? [英] Is "\n" a vertical whitespace, i.e., should "\v" match it?

查看:110
本文介绍了是“\ n”吗?垂直的空白,即应该是“\v”。匹配吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从逻辑上讲,它是(但无论何时角色编码或区域设置正在运行,逻辑都无关紧要)。根据

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";'

打印y,它是。根据

Pattern.compile("\\v").matcher("\n").matches();

在java中返回 false ,但事实并非如此。如果没有此帖子声称

returning false in java, it's not. This wouldn't confuse me at all, if there weren't this posting claiming that


Sun为JDK7更新的Pattern类有一个了不起的新标志UNICODE_CHARACTER_CLASS,这使得一切正常工作。

Sun’s updated Pattern class for JDK7 has a marvelous new flag, UNICODE_CHARACTER_CLASS, which makes everything work right again.

但我使用的是java版本1.7.0_07并且标志存在并且似乎发生了变化什么都没有。而且,\ n不是Unicode的新手,而是一个普通的旧ASCII字符,所以我真的不知道这种差异是如何发生的。可能我做的事情很愚蠢,但是我看不到它。

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.

推荐答案

的Javadoc> java.util.regex.Pattern 在其此类不支持的Perl构造列表中明确提到 \v 。所以不是 \ n 不属于Java的垂直空白类别;这就是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".

编辑添加:相反, \v 代表垂直制表符, U + 000B 。这是一个传统的逃脱序列;还有一些其他传统的转义序列在Java字符串文字中是不允许的,但 Pattern 支持( \ a 用于警报/铃声, \ cX 用于控制字符 X )。但奇怪的是, Pattern 的Javadoc没有提到它支持 \v ;所以我不确定是否可以在所有JDK实现中支持它。

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 by Pattern (\a for alert/bell, \cX for control-character X). Oddly, however, the Javadoc for Pattern fails to mention that it supports \v; so I'm not sure if it can be expected to be supported in all JDK implementations.

这篇关于是“\ n”吗?垂直的空白,即应该是“\v”。匹配吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆