正则指引-字符组demo
class Program
{
static void Main(string[] args)
{
string str = "b";
var result1 = Regex.IsMatch(str, @"2");//字符串比较
var result2 = Regex.IsMatch(str, @"[0123456789]");//字符组穷举
var result3 = Regex.IsMatch(str, @"[0-9]");//范围
var result4 = Regex.IsMatch(str, @"^[0-9]$");//全字符串匹配
var result5 = Regex.IsMatch(str, @"^[0\-9]$");//元字符转义
var result6 = Regex.IsMatch(str, @"^[^0-9]$");//排除字符组
var result7 = Regex.IsMatch(str, @"^\d\w\s$");//简记字符组
var result8 = Regex.IsMatch(str, @"^[\d\w\s]$");//简记字符组,可以用在字符组内部
var result9 = Regex.IsMatch(str, @"^[\D\W\S]$");
//字符组运算
var result10 = Regex.IsMatch(str, @"^[a-z-[aeiou]]$");
Console.WriteLine(result10);
Console.ReadKey();
}
}