日期:2014-05-18  浏览次数:20831 次

求一个正则,不区分大小写以开头匹配5个字符串
问个正则问题``
怎么能让一个字符串跟这5个字符串左边匹配,不区分大小写
"a1/b2/c3/D4/e5"
就是以a1 b2 c3 d45 e5开头的都可以认为是匹配上了
比如
a1 true
b1 false
b234 true
3c false
d456 true
D456 true
d444 false


Regex regex = new Regex(@"^[a1|b2|c3|D4|e5].*$");
Match match = regex.Match(deviceType);
if (match.Success)
{
  success = true;


可以直接在这个代码上改```

------解决方案--------------------
Regex regex = new Regex(@"^((a1)|(b2)|(c3)|(D4)|(e5))*$");
Match match = regex.Match(deviceType);
if (match.Success)
{
success = true;
}
------解决方案--------------------
C# code
string pattern = @"(?i)^(a1|b2|c3|D4|e5).*?$";