求一个正则,不区分大小写以开头匹配5个字符串

limeng_java 2012-03-22 05:17:42
问个正则问题``
怎么能让一个字符串跟这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;
}

可以直接在这个代码上改```
...全文
657 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
limeng_java 2012-03-22
  • 打赏
  • 举报
回复
经过试验,2楼的可以,谢谢大家``等下忙完结贴
_浅浅 2012-03-22
  • 打赏
  • 举报
回复
("^/a|^/b|^/c|^/d|^/e|^")
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复

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

porschev 2012-03-22
  • 打赏
  • 举报
回复


Regex re = new Regex("^((a1)|(b2)|(c3)|(D4)|(e5)).*$", RegexOptions.IgnoreCase);

if(re.IsMatch("你的字符串"))
{
//符合
}
else
{
不符合
}

EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
Regex regex = new Regex(@"^((a1)|(b2)|(c3)|(D4)|(e5)).*$");
Match match = regex.Match(deviceType);
if (match.Success)
{
success = true;
}
少写了个点
  • 打赏
  • 举报
回复
string pattern = @"(?i)^(a1|b2|c3|D4|e5).*?$";
EnForGrass 2012-03-22
  • 打赏
  • 举报
回复
Regex regex = new Regex(@"^((a1)|(b2)|(c3)|(D4)|(e5))*$");
Match match = regex.Match(deviceType);
if (match.Success)
{
success = true;
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧