1、Match:返回的是包含匹配信息的Match对象。
Study("桥架多回路布线自动生成");
public static void Study(string b){
string[] a=new string[]{"多回路布线","预留洞"};
for(int i=0;i<a.Length;i++){
Regex c=new Regex(a[i]);
string d=Convert.ToString(c.Match(b));
if(d!=""&&d!=null){
Report.Info("输出d: "+d);
}
Match e=c.Match(b);
if(e.Success){
Report.Info("匹配成功:"+e.Index);
}
}
}
结果:
2、IsMatch:返回的是布尔值。
Study("桥架多回路布线自动生成");
public static void Study(string b){
string[] a=new string[]{"多回路布线","预留洞"};
for(int i=0;i<a.Length;i++){
Regex c=new Regex(a[i]);
if(c.IsMatch(b)){
Report.Info("输出: "+a[i]);
}
}
}
结果: