I have a syn match
item like this:
syn match txr_num "[+\-]\?\([0-9]\|[0-9][,0-9]*[0-9]\)\?[.]\([0-9]\|[0-9][,0-9]*[0-9]\)\([eE][+\-]\?[0-9]\+\)\?"
Given an input like 1.234e13
it matches only one digit after the decimal point, causing only 1.2
to be colored, regardless of what combination of digits, commas or e
or E
exponent follows that 1.2
.
If I remove the following underlined part of the regex, it handles that case fine; all of 1.234e13
is colored:
syn match txr_num "[+\-]\?\([0-9]\|[0-9][,0-9]*[0-9]\)\?[.]\([0-9]\|[0-9][,0-9]*[0-9]\)\([eE][+\-]\?[0-9]\+\)\?"
^^^^^^^
The subexpression there is this (using more readable regex syntax):
\([0-9]\|[0-9][,0-9]*[0-9]\)
^^^^^^^
This matches either a single digit, or else a digit, followed by a any mixture of digits and periods (including empty) and a digit.
Exactly the same pattern is found before the [.]
, and on that side it works; for instance in the case 123.456
, the 123.4
part is matched.
Somehow, Vim's regex is getting stuck on that underlined term. If it is included, it's as if that whole subexpression is just matching a single [0-9]
, ignoring the branch which matches two or more digits, possibly with interior separating commas.
Am I doing something wrong in that expression anywhere? This is Vim 8.0 on Ubuntu 18.
Update:
Workaround found. It goes away when I exchange the terms of the |
branch:
\([0-9]\|[0-9][,0-9]*[0-9]\) -> \([0-9][,0-9]*[0-9]\|[0-9]\)
Does Vim's regex branch operator some special ordering semantics such that A|B is not always the same as B|A, or is this a bug?
\d
\v
to use very magic mode would probably make these regexs more readable, I think. And you don't need to escape the minus in[+-]
because it's at the end.@dig
. I could make@dig
expand to\d
but it would only make the expansion more readable.:help /bar
.