-1

我需要验证一个范围。输入格式如下:

string example1 = "anydate between 20100101 ~~ 20100101";
string example2 = "anydate between 20100101 and 20100101";
string example3 = "docid between 1 ~~ 2";

我正在使用以下正则表达式:

\b(\w)*(?<operator>Between|contains)\b(?<prefix>.*).*?(?<OP>~~|and)[ ]?\b(?.*)\ b

当用户输入"anydate between 20100101 ~~ 20100101 and test1"失败时,它会捕获 until test1

如何使我的正则表达式不那么贪婪并且只捕获直到20100101

4

1 回答 1

0

你可以试试

anydate\b(?<op>(between|contains))\b(?<first>[0-9]*)\b(?<op2>(~~|and))\b(?<second>[0-9]*)

编辑猜测需要什么但是:

(?<func>\w+)\b(?<op>(between|contains))\b(?<first>\w+)\b(?<op2>(~~|and))\b(?<second>\w+)
于 2011-07-29T20:55:20.963 回答