使用正则表达式我想匹配如下字符串:
我做了@"^3\.\d+[ ]."
但是我想不匹配" 3的字符串。"接下来是单一的1:
我试过@"^3\.[^1][ ]."
,但它不匹配像3.10
那么如何匹配除数字1以外的任何数字?
提前谢谢
答案 0 :(得分:6)
将lookahead assertion与word boundary anchor s:
一起使用@"^3\.(?!1\b)\d+ ."
<强>解释强>
^ # Start of the string
3\. # Match 3.
(?! # Assert that it's impossible to match...
1 # the digit 1
\b # followed by a word boundary (i. e. assert that the number ends here)
) # End of lookahead assertion
\d+ # Then match any number.