lua-users home
lua-l archive

Re: Capture patterns

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I am attempting to capture a series of numbers (all dollar amounts). I have
> experimented with multiple patterns to no avail. I created this small
Perhaps I'm missing something but the program below seems to work.
--lhf
function test(s)
	local a,b,c,d=string.match(s,"(.-)%s+(%S+)%s+(%S+)%s+(%S+)$")
	print(s)
	print(a)
	print(b)
	print(c)
	print(d)
	print()
end
line_data={}
line_data[1] = "This is good data 4.00 3.99 (1,768.50)"
line_data[2] = "Data- In a line 5.00 (100,000.00) 957,123.45"
line_data[3] = "Repairs- () (Wages) 123,456.99 28,123.45 650.00"
line_data[4] = "Repairs- Ex. Wages 50,120.00 500.00 1,000.00"
line_data[5] = "A bunch of negatives (123,456.89) (123,456.90) (123,456.91)" 
for i = 1, #line_data do
print(test(line_data[i]))
end

AltStyle によって変換されたページ (->オリジナル) /