I think this regex will also give false positives, because it would now also match something like '+cm'.
There is no way around the '|' I think, because the decimal part is what you might call optionally optional; it is only optional if there is a whole part of the number. Because of this, you can't always use the ? modifier to make the decimal part optional.
The only other ways I could think of would use experimental regex features. Even zero-width look-behind or look-ahead assertions can't be aplied here I think...
But I've finally been referenced by name on Perlmonks! Made my day!
:) |