这是我的尝试:
Java:
public static void main(String[] args) {
String text = "This && is **^^ a ~~@@ test.";
System.out.println(Pattern.compile("\\p{Punct}").matcher(text).replaceAll(""));
// OUT: This is a test --> As I expected
}
C#:
static void Main(string[] args) {
string text = "This && is **^^ a ~~@@ test.";
Console.WriteLine(Regex.Replace(text, "\\p{P}", ""));
// OUT: This is ^^ a ~~ test
// expected: This is a test
Console.ReadLine();
}
有什么想法吗?谢谢!
最佳答案
"\\p{P}"
Java 中的意思相同和 C# ,即匹配 Unicode 类别 P
(标点符号)。
Java 的 "\\p{Punct}"
意味着别的东西,是 documented如:
Punctuation: One of
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
因此,等效的 C# 是 "[!\"#$%&'()*+,\\-./:;<=>?@\\[\\\\\\]^_`{|}~]"
关于java - 在 Java 和 C# 中使用 POSIX 删除所有标点符号会产生不同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53598873/