> > 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).