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]$");string
//字符組運算
var result10 = Regex.IsMatch(str, @"^[a-z-[aeiou]]$");it
Console.WriteLine(result10);io
Console.ReadKey();
}
}class