Why can't I match POSIX character classes

The following snippet prints False:

Console.WriteLine(Regex.IsMatch("abc", @"[[:alpha:]]"));

But this prints True:

Console.WriteLine(Regex.IsMatch("abc", @"[a-zA-Z]"));

Why? Shouldn't they be equivalent?

+5
source share
1 answer

.NET Regexes do not support Posix character classes. However, they do support Unicode groups.

This will work:

Regex.IsMatch("abc", @"^\p{L}+$");

The group \p{L}matches all Unicode characters.

See here for more information:

http://msdn.microsoft.com/en-us/library/20bw873z.aspx#CategoryOrBlock

+8
source

All Articles