in reply to Re: Identifying and parsing numbers
in thread Identifying and parsing numbers

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!

:)

  • Comment on Re: Re: Identifying and parsing numbers

Replies are listed 'Best First'.
Re: Re: Re: Identifying and parsing numbers
by Gilimanjaro (Hermit) on Jan 16, 2003 at 23:53 UTC
    Though I was dumb enough to actually post will not being logged in... There go my votes... ;)
Re: Identifying and parsing numbers
by tekkie (Beadle) on Jan 17, 2003 at 14:37 UTC
    Ah, yes, you are absolutely correct, I overlooked the fact that doing:

    (\d*(?:\.\d+)?)

    Would allow both the whole number and the decimal portions to match 'nothing at all' as I so aptly described in my breakdown.

    One more case of testing too many things that should work and not enough things that shouldn't.