C# equivalent of Java Punctuation regex

后端 未结 2 1997
悲哀的现实
悲哀的现实 2021-01-14 05:59

I\'m looking to find the equivalent in C# for the equivalent of this regex.

Java:

public static final String expression = \"[\\\\s\\\\p{Punct}]\";


        
相关标签:
2条回答
  • 2021-01-14 06:12

    Use this:

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

    Note in particular the use of @.

    0 讨论(0)
  • 2021-01-14 06:32

    [\s\p{P}] matches all whitespace and punctuation. Amusingly enough, it can be found in this exact form as an example in the MSDN documentation on Character Classes. As in Java, \p{x} is used for any single character from unicode category x. See the part on Unicode Categories for a list of the possibilities other than P.

    0 讨论(0)
提交回复
热议问题