[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Capture patterns
- From: KHMan <keinhong@...>
- Date: Wed, 09 Jan 2008 10:03:07 +0800
Eric Tetz wrote:
> On Jan 8, 2008 7:04 AM, Jeff Wise <email@example.com> wrote:
>> Look at all these possible formats:
> If you strip out the superfluous characters:
> Or you could use one pattern and test if you caught any of the extra stuff:
> function match_number(s)
> s = s:gsub("[$,+%s]", "") -- strip garbage
> local pre, n, post = s:match("([-(]?)(%d*%.%d+)([CR-]?)")
> return (pre ~= "" or post ~= "") and -n or n
A minor quibble...
Any attempt at converting a financial figure to a floating point
representation without scaling gets me really worried... it might
work now, but somewhere down the line, extra processing tacked in
by a later developer trusting the data integrity of the input
layer might cause some values to go off by a wee bit.
In this case, I think Jeff just needs them as strings or lightly
processed strings and I do think not converting the figures is safer.
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia