-1

Looking to build regex any positive/negative decimal empty string allowed.

re.match('^[0-9\+\-\.]*$', i)

The regex captioned above allows for "+" or "-" or "." singular instance.

at entry "+" or "-" or "." not permissible.

niro
  • 1
  • 4

1 Answers1

0

+ and - should only be allowed at the beginning, not anywhere in the number. Then you can make the decimal point followed by additional digits optional at the end. And to allow an entirely empty string, make the whole thing optional.

re.match(r'^(?:[-+]?[0-9]+(?:\.[0-9]*)?)?$', i)
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thats awesome dude. just came up with this ^(?!\+)(?!\-)(?!\.)[0-9\+\-\.]*$. it fails it allows "-2.-2.0" Cheers Mr.B – niro Mar 20 '20 at 06:44