Match with Regex any number except a specific number -


using regex match strings like:

  • 3.2 title 1
  • 3.5 title 2
  • 3.10 title 3

i did @"^3\.\d+[ ]." not match strings of "3." followed single 1 :

  • 3.1 title 4

i tried @"^3\.[^1][ ]." doesnt match strings 3.10

so how can match numbers except number 1?

thank in advance

use lookahead assertion word boundary anchors:

@"^3\.(?!1\b)\d+ ." 

explanation:

^   # start of string 3\. # match 3. (?! # assert it's impossible match...  1  # digit 1   \b # followed word boundary (i. e. assert number ends here) )   # end of lookahead assertion \d+ # match number. 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -