RegEx查找字符串是否首先包含字符,然后是数字

时间:2014-06-06 11:22:29

标签: c# regex

任何人都可以告诉我应该使用哪种模式来跟随字符串格式:

  1. 第一个角色总是' C'或者' c'
  2. 之后1-4个数字数字
  3. 然后' _'
  4. 最后再一系列一些角色(没有固定)
  5. 例如:C10_COMC1122_ABC etc

    在c#中Regex.IsMatch()

1 个答案:

答案 0 :(得分:3)

试试这个:

^[cC][0-9]{1,4}_.*$

其中:

^ = Start of the line
[cC] = either upper or lowercase c
[0-9]{1,4] = Match a number 1 to 4 times
_ = underscore
.* = Any number of characters
$ = end of line

附录:您没有指定是否允许您在行尾添加零字符。如果没有,请将.*替换为?*

相关问题