From: CyberFrog on
Hi,
I have been practicing the various different regexp formats you can get but now I'm getting confused. Can someone tell me how to best format and match a simple number with a decimal place i.e. 0. , -3.9, 1.99999, 1.0, 2. , -999. etc the numbers I would like to match can of course vary, the best I can do is:

regexp(str,'s*.\s*','match)

just wondering if there is anything that is alot more precise and accurate?

thanks
cf
From: Walter Roberson on
CyberFrog wrote:

> I have been practicing the various different regexp formats you can get
> but now I'm getting confused. Can someone tell me how to best format
> and match a simple number with a decimal place i.e. 0. , -3.9, 1.99999,
> 1.0, 2. , -999. etc the numbers I would like to match can of course
> vary, the best I can do is:
>
> regexp(str,'s*.\s*','match)
>
> just wondering if there is anything that is alot more precise and accurate?

[-+]?\d*\.?\d*
From: Rune Allnor on
On 17 apr, 20:52, "CyberFrog" <domle...(a)hotmail.com> wrote:
> Hi,
> I have been practicing the various different regexp formats you can get but now I'm getting confused.  Can someone tell me how to best format and match a simple number with a decimal place i.e. 0. , -3.9, 1.99999, 1.0, 2. , -999. etc  the numbers I would like to match can of course vary, the best I can do is:
>
> regexp(str,'s*.\s*','match)
>
> just wondering if there is anything that is alot more precise and accurate?

The book

Friedl: "Mastering Regular Expressions"

spends a couple of pages discussing how to handle floating-point
numbers. One needs to be a bit careful how to specify this, as
there are a couple of very subtle traps one can easily fall into.

Get a copy of that book. It's indispensable if you use regular
expressions.

Rune
From: Rune Allnor on
On 17 apr, 20:55, Walter Roberson <rober...(a)hushmail.com> wrote:
> CyberFrog wrote:
> > I have been practicing the various different regexp formats you can get
> > but now I'm getting confused.  Can someone tell me how to best format
> > and match a simple number with a decimal place i.e. 0. , -3.9, 1.99999,
> > 1.0, 2. , -999. etc  the numbers I would like to match can of course
> > vary, the best I can do is:
>
> > regexp(str,'s*.\s*','match)
>
> > just wondering if there is anything that is alot more precise and accurate?
>
> [-+]?\d*\.?\d*

Nope.

In the above, the sign may or may not exist. Any number of digits
(including none) may exist, a decimal point may or may not exist,
then another arbitrary-length sequence (including none) of digits
may exist.

Everything is optional, nothing required.

*The* trap Friedls mentioned and why he spends a lot of space
discussing the problem.

Rune
From: CyberFrog on
Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <c459207b-5549-40c0-8700-6762abe99996(a)c21g2000yqk.googlegroups.com>...
> On 17 apr, 20:55, Walter Roberson <rober...(a)hushmail.com> wrote:
> > CyberFrog wrote:
> > > I have been practicing the various different regexp formats you can get
> > > but now I'm getting confused.  Can someone tell me how to best format
> > > and match a simple number with a decimal place i.e. 0. , -3.9, 1.99999,
> > > 1.0, 2. , -999. etc  the numbers I would like to match can of course
> > > vary, the best I can do is:
> >
> > > regexp(str,'s*.\s*','match)
> >
> > > just wondering if there is anything that is alot more precise and accurate?
> >
> > [-+]?\d*\.?\d*
>
> Nope.
>
> In the above, the sign may or may not exist. Any number of digits
> (including none) may exist, a decimal point may or may not exist,
> then another arbitrary-length sequence (including none) of digits
> may exist.
>
> Everything is optional, nothing required.
>
> *The* trap Friedls mentioned and why he spends a lot of space
> discussing the problem.
>
> Rune

Cheers Rune and Walter, okay after much perserverance and considering your ideas I have eventually opted for this expression which seems to be quite precise:

regexp(mystring, '\s[-]?+[0-9]+\.[0-9]?\s', 'match')

Thanks for your expertise!