fork download
  1. import re
  2. n = r'[01](?:\.[0-9]{1,8})?'
  3. rx = re.compile(fr"\[(-?(?!0(?:\.0+)?{n}\s))\s+(-?(?!0(?:\.0+)?]){n})]")
  4. test_strs = ["[-0.19666128 -0.0000]","[-1.09666128 -0.16812956]","[-0.180045 -0.22017317]", "[1.00000786 -0.24855652]", "[0.1766060 -1.]", "[1.16797414 0.00000000e+00]",
  5. "[-0. 0.]", "[1.1223297 -0.2840327]","[1. -0. ]", "[-0.11070672 -0.20553467]","[1.04924586 -0.16772696]"
  6. "[0.06169098 -0.15855075]","[-0.11988816 1.20512903]","[-0.180045 -1.22017317]","[-0.18486786 -0.24855652]"]
  7. for text in test_strs:
  8. if rx.search(text):
  9. print(f'{text}: Valid')
  10. else:
  11. print(f'{text}: Invalid')
  12.  
Success #stdin #stdout 0.02s 9680KB
stdin
Standard input is empty
stdout
[-0.19666128 -0.0000]: Invalid
[-1.09666128 -0.16812956]: Invalid
[-0.180045 -0.22017317]: Invalid
[1.00000786 -0.24855652]: Invalid
[0.1766060 -1.]: Invalid
[1.16797414 0.00000000e+00]: Invalid
[-0. 0.]: Invalid
[1.1223297 -0.2840327]: Invalid
[1. -0.       ]: Invalid
[-0.11070672 -0.20553467]: Invalid
[1.04924586 -0.16772696][0.06169098 -0.15855075]: Invalid
[-0.11988816 1.20512903]: Invalid
[-0.180045   -1.22017317]: Invalid
[-0.18486786 -0.24855652]: Invalid