regexvim

Why does a regex that ends with `[^.]` match unexpectedly?


Consider following line (like in a table of contents):

6.1.34.2    Some text

(there is a tab after the "2").

When searching for ^\d\+[.]\d\+[.]\d\+[^.] the line is selected (and colored from "6" to "4"), which IMHO is not correct due to the last dot in the testcase.

With ^\d\+[.]\d\+[.]\d\+\s the line is not selected (as expected).

My question is, what is wrong with the first regex?


Solution

  • \d\+[^.]

    Here, \d\+ matches the 3, and [^.] matches the 4.

    You seem to expect that \d\+ matches 34 and then [^.] will not match the .. I'm not sure if that expectation is reasonable (i.e., whether \d\+ has to be greedy).