择一匹配
字符 说明
| 将两个匹配条件进行逻辑“或”(Or)运算。
example
//查找数字或字母
string s = "34((**apple厉害厉害";
string pattern = @"\d|[a-z]"; //匹配数字或者字母
MatchCollection col = Regex.Matches(s,pattern);
foreach(Match match in col)
Console.Write(match.ToString());
//输出为34apple
//将人名输出
//不使用择一匹配
string s = "zhangsan,lisi;wangwu.zhailiu";
string pattern = @"[;,.]";
string[] resArray = Regex.Split(s, pattern);
foreach (var s1 in resArray)
Console.WriteLine(s1);
//使用择一匹配
string s = "zhangsan,lisi;wangwu.zhailiu";
string pattern = @"[;]|[,]|[.]";
string[] resArray = Regex.Split(s, pattern);
foreach (var s1 in resArray)
Console.WriteLine(s1);
//二者的输出结果相同,都为
//zhangsan
//lisi
//wangwu
//zhaoliu