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"

为什么?

4

2 回答 2

2

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

从正则表达式中删除^and$会给你你想要的。

于 2013-11-13T08:05:10.247 回答
0
  1. [A-Za-z0-9]{0,10} 将只允许从 a 到 z A 到 Z 和从 0 到 9 的 10 个字母表

  2. 所以它的好习惯是通过正则表达式放置固定数量的字母匹配。

于 2013-11-13T09:53:08.753 回答