I have an item of equipment that returns a torque value in either Nm or lbf ft. The serial connection may sometimes be flaky, so I'd like to reject any string that is not valid. Regex is excellent for this but I'm getting some false positives
A valid string comprises of:
The torque value of zero to 999 to two decimal places, a space, then N<space>m or lbf<space>ft. There is no leading zero.
i.e. "0.57 N m" or "1.43 lbf ft" or "49.38 N m" or "647.03 lbf ft"
I'm almost there with a Regex search string of "^[0-9]{1,3}\.[0-9]{2} N m| lbf ft$" but my false positives are where there are extra characters before or after the valid string. I thought by topping and tailing with ^ and $ woul prevent it.
(Although leading zeros are strictly invalid, I can live with those as false positives for now)
A valid string comprises of:
The torque value of zero to 999 to two decimal places, a space, then N<space>m or lbf<space>ft. There is no leading zero.
i.e. "0.57 N m" or "1.43 lbf ft" or "49.38 N m" or "647.03 lbf ft"
I'm almost there with a Regex search string of "^[0-9]{1,3}\.[0-9]{2} N m| lbf ft$" but my false positives are where there are extra characters before or after the valid string. I thought by topping and tailing with ^ and $ woul prevent it.
(Although leading zeros are strictly invalid, I can live with those as false positives for now)