Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: António Lopes
  Where is António Lopes?
 Coimbra
 Portugal
 António Lopes
 To: Tony Vignone
  Where is Tony Vignone?
 St Augustine
 Florida - United States
 Tony Vignone
Subject: RE: Search String Parsing
Thread ID: 436086 Message ID: 436142 # Views: 49 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Friday, April 29, 2016 5:24:42 PM         
   



> > FUNCTION GetQuantity (tcText AS String, tcUnits AS String)
> >
> > IF !"\_REGEXP.VCX" $ SET("Classlib")
> > SET CLASSLIB TO (ADDBS(HOME(1)) + "ffc\_regexp.vcx") ADDITIVE
> > ENDIF
> >
> > LOCAL loRegExpr AS _regexp
> >
> > m.loRegExpr = CREATEOBJECT("_regexp")
> > m.loRegExpr.Pattern = "\d+(\.\d+)*\s*(" + m.tcUnits + ")"
> >
> > RETURN IIF(m.loRegExpr.Execute(m.tcText,.F.) = 1, VAL(m.loRegExpr.Matches[1,2]), .NULL.)
> >
> > ENDFUNC
> >
>
> Good job. Well done
>
> I would have used
>
>
> 	m.loRegExpr.Pattern = "\d\d*\s*(" + m.tcUnits + ")"

> I don't understand the (\.\d+)*
> Can you explain for me?
>
> Tony

Sure, Tony. It matches the fractional part of the quantity, if there is one. Without it, 8.5 oz would be fetched as 5 oz.

As I'm looking into it, a minor correction in the pattern: \d+(\.\d+)? (that is, ? instead of *, since we don't want the group to occur more than once).

ENTIRE THREAD

Search String Parsing Posted by Pete Sass @ 4/28/2016 4:59:03 PM
RE: Search String Parsing Posted by António Lopes @ 4/28/2016 6:03:33 PM
RE: Search String Parsing Posted by Tony Vignone @ 4/29/2016 5:09:56 PM
RE: Search String Parsing Posted by António Lopes @ 4/29/2016 5:24:42 PM
RE: Search String Parsing Posted by Tony Vignone @ 4/29/2016 5:39:57 PM
RE: Search String Parsing Posted by António Lopes @ 4/29/2016 5:51:46 PM
RE: Search String Parsing Posted by Tony Vignone @ 4/29/2016 8:36:52 PM
RE: Search String Parsing Posted by Pete Sass @ 5/1/2016 6:41:17 PM