您的位置:首页 > 其它

择一匹配

2015-12-15 22:15 204 查看
| 将两个匹配条件进行逻辑“或”(Or)运算。

示例一:查找数字或字母

string findStr1 = "ad(d3)-df";

string regexFindStr = @"[a-z]|\d";

string newStrFind=String.Empty;

MatchCollection newStr =  Regex.Matches(findStr1, regexFindStr);

 newStr.Cast<Match>().Select(m => m.Value).ToList<string>().ForEach(i => newStrFind += i);

Console.WriteLine(findStr1 + "中的字母和数字组成的新字符串为:" + newStrFind);

示例二:将人名输出("zhangsan;lisi,wangwu.zhaoliu")

string strSplit = "zhangsan;lisi,wangwu.zhaoliu";

string regexSplitstr = @"[;]|[,]|[.]";

Regex.Split(strSplit, regexSplitstr).ToList().ForEach(i => Console.WriteLine(i));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  正则表达式