Sorry guys I've made these posts as clear as mud. I am asking two questions.
Question 1.
The code I am trying to make work is:
for v in io.lines([[c:\speeds.txt]]) do
for k,w in string.gmatch(v,"=(%w*)=") do
Note(w)
end
end
speeds.txt looks like this:
==1==Armory==Gueldar's Armory==2s3wn==
==2==Bakery==The Aylorian Eatery==2s3en==
==3==Bank==The Aylorian Bank of Ivar==11s==
The regex above matches the whole line and I can't figure out how to get it to match one part of a line at a time. I need to break speeds.txt into four parts per line, Number, Name, Disc, Speedwalk. I can't get my head around this. "=" is an alphanumeric so it matches the whole line, is there a better character I should use to mark the sections of speeds.txt. Or can a regex match each part of the line with no character marking the beginning and end of each section?
I have tried [] ranges to avoid matching the whole line and even tried using the exact words "==(1)==(Armory)==(Gueldar's Armory)==(2s3wn)==" to test and still can't match each section. As I understand gmatch should should match 4 times on the first line using "==(1)==(Armory)==(Gueldar's Armory)==(2s3wn)==" and iterate 4 times returning what is between the brackets. How ever when returns "Armory" twice when I try this.
Question 2.
If I run:
t = {}
s = "from=world, to=Lua"
for k, v in string.gmatch(s, "(%w+)=(%w+)") do
t[k] = v
end
for i,v in pairs(t) do Note(t[i]) end
And I get output:
Lua
world
Is this code working correctly. As I understand gmatch with regex it should give the out put:
from
world
to
Lua
Sorry for all the confusion and thanks for the help. |