查找替换制表符\\t,为啥这三种写法都可以

String.replaceFirst中第一个参数是一个正则表达式, 正则表达式如果直接硬编码在代码里,作为Literal String,首先会被JVM进行Escape处理,然后被正则表达式引擎处理"\\t"首先会被Escape成"\\u0009",Tab字符的Unicode, 在Java里面可直接作为正则表达式使用,注意看java.util.Pattern的JavaDoc Pattern (Java Platform SE 7 )Unicode escape sequences such as \\u2014 in Java source code are processed as described in section 3.3 of The Java? Language Specification. Such escape sequences are also implemented directly by the regular-expression parser so that Unicode escapes can be used in expressions that are read from files or from the keyboard. Thus the strings "\\u2014" and "\\\\u2014", while not equal, compile into the same pattern, which matches the character with hexadecimal value 0x2014."\\\\\\t" 被JVM处理后作为"\\\\u0009"传进正则表达式,在"\\"之后的字符,正则表达式引擎认为如果不能被Escape,则表示字符本身,即 "\\\\u0009"和"\\u0009"是等价的"\\\\t" 被JVM处理后作为"\\t"传进正则表达式引擎,这个是正常的正则表达式语法,匹配一个制表符
■网友
问问楼主你这啥编辑器啊,怪漂亮的。
■网友
恭喜题主发现了Javac的一个bug


    推荐阅读