我无法弄清楚我的正则表达式有什么问题?

时间:2013-11-13 08:02:38

标签: regex c#-4.0

下面是有问题的代码:

ID = null;
Table = null;

Match CMD = Regex.Match(CommandString, @"create update command for (^[A-Za-z0-9 ]+$) Where_ID_=_(^[0-9]+$)"); //create update command for MARKSWhere_ID_=_11

if (CMD.Success)
{
    Table = CMD.Groups[1].Value;
    ID = CMD.Groups[2].Value;

    return true;
}

每次

时返回false
CommandString = "create update command for MARKS Where_ID_=_5"

为什么?

2 个答案:

答案 0 :(得分:2)

在您使用的正则表达式中,^表示输入字符串的开头,$表示输入字符串的结尾。

从正则表达式中删除^$将为您提供所需内容。

答案 1 :(得分:0)

  1. [A-Za-z0-9] {0,10}只允许10个字母表从a到z A到Z和从0到9

  2. 通过正则表达式确定字母匹配数量的好习惯。

相关问题