[英]C# equivalent of Java Punctuation regex
I'm looking to find the equivalent in C# for the equivalent of this regex. 我希望在C#中找到相当于这个正则表达式的等价物。
Java: Java的:
public static final String expression = "[\\s\\p{Punct}]";
{Punct}
is a reserved character class in Java but I'm not sure how to create the equivalent expression so that the .net regex engine doesn't barf. {Punct}
是Java中的保留字符类,但我不确定如何创建等效表达式,以便.net正则表达式引擎不会barf。
[\\s\\p{P}]
matches all whitespace and punctuation. [\\s\\p{P}]
匹配所有空格和标点符号。 Amusingly enough, it can be found in this exact form as an example in the MSDN documentation on Character Classes . 有趣的是,它可以在这个确切的形式中找到,作为关于字符类的MSDN文档中的一个例子。 As in Java,
\\p{x}
is used for any single character from unicode category x
. 与在Java中一样,
\\p{x}
用于unicode类别x
任何单个字符。 See the part on Unicode Categories for a list of the possibilities other than P
. 有关除
P
以外的可能性列表,请参阅Unicode类别的部分。
Use this: 用这个:
Regex regex = new Regex(@"[\s\p{P}]");
Note in particular the use of @
. 特别注意使用
@
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.