Reputation: 4307
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
Upvotes: 1
Views: 147
Reputation: 170148
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
Upvotes: 2