xKiv
Active member
I wonder if xKiv's regex recognizes negative numbers?
"(?<!\\s)([\\d,]+)(?!\\s)" will not match a negative number, unless there is a space between the minus sign and the humber itself, because ...
... wait, I think I got it wrong ... I put in negative look*s, because I wanted it to work at the start/end of the string too, but I forgot to negate the character class!
This regex will actually only match a number that *doesn't* have a space on any end.
Correct version would be ...
"(?<!\\S)([\\d,]+)(?!\\S)"
(replace lowercase s with uppercase S)
Now, this will find a (maximal) string of digits (and the character ",") such that it isn't preceded by a non-space character and isn't followed by a non-space character (which is much the same as "is preceded by a space or a start of string AND is followed by a space or a start of string" .. which could have probably been more succintly expressed as "(^|\\s)([\\d,]+)($|\\s)" but that would change the capture groups), so it won't match anything directly preceded (or containing) a "-" character.
For the possibility of that, you would want something like
"(?<!\\S)(-?[\\d,]+)(?!\\S)"