与正则表达式匹配除特定号码之外的任何号码

use*_*493 3 regex

使用正则表达式我想匹配如下字符串:

  • 3.2标题1
  • 3.5标题2
  • 3.10标题3

我做了@"^3\.\d+[ ]." 但是我想不匹配"3"的字符串.接着是单一的1:

  • 3.1标题4

我试过@"^3\.[^1][ ]."但它不匹配像3.10这样的字符串

那么如何匹配除1号以外的任何数字?

先感谢您

Tim*_*ker 6

使用带有字边界锚 s 的前瞻断言:

@"^3\.(?!1\b)\d+ ."
Run Code Online (Sandbox Code Playgroud)

说明:

^   # 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.
Run Code Online (Sandbox Code Playgroud)