Einzelnen Beitrag anzeigen

SProske

Registriert seit: 16. Feb 2015
Ort: Halle/S.
116 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#8

AW: RegExpr to detect integers

  Alt 17. Apr 2015, 11:26
(?<!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.
Sebastian

Geändert von SProske (17. Apr 2015 um 11:33 Uhr)
  Mit Zitat antworten Zitat