AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

RegExpr to detect integers

Ein Thema von WojTec · begonnen am 16. Apr 2015 · letzter Beitrag vom 17. Apr 2015
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

Re: RegExpr to detect integers

  Alt 16. Apr 2015, 15:01
Oh, I understand. I simply thought that it is possible with regex. Thanks a lot!
  Mit Zitat antworten Zitat
SProske

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

AW: RegExpr to detect integers

  Alt 16. Apr 2015, 16:11
You could use the following RegEx for a positive check:

Code:
(?<!\.|\,|\d)([-+]?\d+)(?!\d*[\.|\,]\d*)
https://regex101.com/r/yU2vY2/1
Sebastian
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#3

Re: RegExpr to detect integers

  Alt 17. Apr 2015, 11:14
Thanks

BTW: what mean ?<! ?!, because there are not literal symbols I think? Something like 'can't be behind string looking for' or 'con't start with'?
  Mit Zitat antworten Zitat
SProske

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

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
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz