小编wil*_*iam的帖子

正则表达式 (?U)\p{Punct} 缺少 Java 中的一些 Unicode 标点符号

首先,我想删除字符串中的所有标点符号。我写了下面的代码。

\n
Pattern pattern = Pattern.compile("\\\\p{Punct}");\nMatcher matcher = pattern.matcher("!\\"#$%&\'()*+,-./:;<=>?@[\\\\]^_`{|}~\xef\xbc\x88hello\xef\xbc\x89");\nif (matcher.find())\n    System.out.println(matcher.replaceAll(""));\n
Run Code Online (Sandbox Code Playgroud)\n

替换后我得到了这个输出:\xef\xbc\x88hello\xef\xbc\x89

\n

!"#$%&\'()*+,-./:;<=>?@[\\]^_因此该模式与{|}~`之一匹配,它与官方文档匹配。

\n

但我也想删除“\xef\xbc\x88”Fullwidth Left Parenthesis U+FF08*和“\xef\xbc\x89” Fullwidth Right Parenthesis U+FF09,所以我将代码更改为:

\n
Pattern pattern = Pattern.compile("(?U)\\\\p{Punct}");\n        Matcher matcher = pattern.matcher("!\\"#$%&\'()*+,-./:;<=>?@[\\\\]^_`{|}~\xef\xbc\x88\xef\xbc\x89");\n        if (matcher.find())\n            System.out.println(matcher.replaceAll(""));\n
Run Code Online (Sandbox Code Playgroud)\n

替换后,我得到以下输出:$+<=>^|~`

\n

它确实匹配了 "\xef\xbc\x88"Fullwidth Left Parenthesis U+FF08*和 "\xef\xbc\x89" Fullwidth Right Parenthesis U+FF09,但它错过了$+<=>^|~`。

\n

我感到很困惑。为什么会发生这种事?有人可以提供一些帮助吗?

\n

java regex unicode

6
推荐指数
1
解决办法
279
查看次数

标签 统计

java ×1

regex ×1

unicode ×1