I'm looking to find the 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 the equivalent expression so that the .net regex engine doesn't barf.
[\\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
.
Use this:
Regex regex = new Regex(@"[\s\p{P}]");
Note in particular the use of @
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.