(?<!
XXX) is a negative lookbehind, it checks, that there is nothing fitting
XXX directly before the captured string.
In your case it checks, that there is no ".", "," or any number.
(?!
XXX) is a negative lookahead, it checks, that there is nothing fitting
XXX directly behind the captured string.
In your case it checks, that there is not any amount (including 0) of numbers followed by "." or "," followed by any amount (including 0) of numbers
For further information you might check:
http://www.regular-expressions.info/lookaround.html
E:
Just a little improvement on the regex:
Code:
(?<!\.|\,|\d)([-+]?\d+)(?!\d*[\.|\,]\d+)
The one before failed on: "My favourite number is 7."
This one captures a number, that is followed by a "." or "," but not a number again.