正则表达式使用收集

应公司最近的要求,在做一个题库系统,对答案的格式采用了正则表达式进行过滤,

1. Regex re = new Regex(@"^(?!.*(.).*1)[ABCD]{1,4}$"); 限定只能输入ABCD 且任意一个字符不能重复出现二次以上
2.Regex re = new Regex(@"[A-Z]+"); 对答案进行过滤提取 只取存在ABCD字符的内容
string SAnswer = "";//标准正确答案
string EAnswer = "";//作答答案
MatchCollection mc = re.Matches(examKp.Value.ToUpper());
foreach (Match m in mc)
{
EAnswer += m.Value;
}
mc = re.Matches(detailInfo.Answer.ToUpper());
foreach (Match m in mc)
{
SAnswer += m.Value;
}
if (EAnswer.StringEqualsForSimplified(SAnswer))
{
isRight = true;
}



原文地址:https://www.cnblogs.com/gudaozi/p/6688735.html