需要帮助构建正则表达式

时间:2010-12-20 13:11:24

标签: c# regex

的正则表达式是什么
OD
-0D

-123D

-145Y

234w

and not +234D or -678m etc.

我确实

string EXP_REGEX_VALID_LITERAL = @"[0-9]*[d|D|w|W|m|M|q|Q|y|Y]";
Regex regex = new Regex(EXP_REGEX_VALID_LITERAL);
return regex.IsMatch(inputString);

但是"/0345d"

失败了

验证规则:

表达式是字母数字(字母表是可选的),其中字母表只能是d | D | w | W | m | M | q | Q | y | Y并且只能出现在数字之后。此外,如果任何字符可以出现在任何只能是减号的数字之前.so-123有效或-123d或123d或123w有效。但不是23dw或+ 12d等。

由于

1 个答案:

答案 0 :(得分:2)

如果我很清楚你想要什么,可能会有效:

/^-?\d+[dwmqy]$/i

c#语法(不太确定):

Regex.Match("/0123d", "^-?\d+[dwmqy]$",RegexOptions.IgnoreCase);

其中:

^   begining of the string
-?  optionnal -
\d+ one or more digits
[dwmqy]  one of these char
$   end of the string

i   case insensitive