Sur*_*aju 11 java regex unicode utf-8
为什么下面的代码与印度语言不起作用(导致错误)?
System.out.println(Charset.forName("UTF-8").encode("??????")
.asCharBuffer().toString().matches("\\p{L}+"));
System.out.println(Charset.forName("UTF-8").encode("??????")
.asCharBuffer().toString().matches("\\p{L}+"));
System.out.println(Charset.forName("UTF-8").encode("???????")
.asCharBuffer().toString().matches("\\p{L}+"));
Run Code Online (Sandbox Code Playgroud)
以上所有代码都返回false.这个正则表达式有什么问题?如何验证世界上任何unicode角色?
\p{Letter}只捕获字母,但您还需要标记,您可以使用\p{Mark}.
System.out.println("??????".matches("[\\pL\\pM]+"));
Run Code Online (Sandbox Code Playgroud)