lua-users home
lua-l archive

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


On Tue, Dec 18, 2012 at 10:55 AM, ranier@cultura.com.br <ranier@cultura.com.br> wrote:
Hello All,
Sorry, I´m newbie in lua programming.

Anybody can help with pattern to process http://www.bcb.gov.br/rex/ftp/paises.txt
I would like split in two variables s1 and s2
s1 = 00132
s2 = AFEGANISTAO

----------------------------------------------------------------------------------
local pat = "(%S+)%s+(%S+)"

for s1, s2 in string.gmatch(io.read("*all"), pat) do
   print(s1, s2)
end
----------------------------------------------------------------------------------

Best regards,

Ranier Vilela

Hello Ranier,

From what I see in the file you mentioned, I think we can deduce a more specific pattern that might be simpler.

I would use myself would be something that captures simply 5 digits, then a space character, then everything until the end of the line.

Have you had the opportunity to take a look here: http://www.lua.org/pil/20.2.html ?

Cheers,

-- Alessandro