1
votes
local invoiceData =
[[I N V O I C E
Invoice No. :
ABCDEFG125469857
Invoice Date May
2012
]]

The pattern I am using is

 print (string.match(invoiceData,'\nInvoice Date (.-)\n'))

I want to fetch the string invoice date as MAY12. or 0512.. please help

Thanks

1

1 Answers

2
votes

Instead of matching with .-, be more specific and use %w+ (alpha-nums) and %d+ (digits) to match the month and year.

The script:

local invoiceData =
[[I N V O I C E
Invoice No. :
ABCDEFG125469857
Invoice Date May
2012
]]

month, year = string.match(invoiceData,'Invoice%s+Date%s+(%w+)%s+%d*(%d%d)')
print(month, year)

will print:

May    12