C # Java Punctuation regex equivalent

I am looking to find an equivalent in C # for the equivalent of this regex.

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 an equivalent expression, so the .net regex engine does not work.

+3
source share
2 answers

[\s\p{P}] matches all spaces and punctuation. Funnily enough, you can find it in this exact form as an example in the MSDN documentation on Character Classes . As in Java, \p{x} used for any single character from the unicode x category. See the Unicode Categories section for a list of features other than P

+3
source

Use this:

 Regex regex = new Regex(@"[\s\p{P}]"); 

Pay particular attention to the use of @ .

+3
source

All Articles