Oct-17-2020, 05:48 PM
Why not just keep the minus symbol with your number? Then, I think you don't care if it's positive or negative, you just print it.
res = r'X(-?\d+\.\d*)
>>> re.search(r'X(-?\d+\.\d*)', "Z1.371 Y-1.279 X-0.0003").groups()[0] '-0.0003' >>> re.search(r'X(-?\d+\.\d*)', "Z1.371 Y-1.279 X0.0003").groups()[0] '0.0003'