Matching Question

Posted by Nate7240 on Wed 10 Mar 2010 10:56 PM — 3 posts, 12,121 views.

#0
Alright so I've created a mini window that displays a map that is given to me through the output on the game Aetolia. Now, it does exactly what I want it to(omits the map from the output and redirects it into the miniwindow) but only when I tell it specifically where the map starts and where the map ends. Here is a chunk of code to help (note, this is based off of Nick's inventory alias):

Checks to see if map starts

-- Waiting for map to start

local x = wait.match ("---------- v10009 -----------", 5)

if not x then
  ColourNote ("white", "blue", "No map received within 5 seconds")
  return
end -- if


Checks to see if end of map

   -- Check to see if end of map
   if string.match (line, "^----------- 4:2:0 -----------") then
   break
   end -- if


now the start lines(---------- v10009 -----------) and end lines(----------- 4:2:0 -----------) can vary, but not by much I believe. The problem is that I can't make those two lines match in different rooms because the numbers change. I was thinking that you most likely need to use regular expressions, but being as I am not the brightest crayon in the box, I need your help. Will be greatly appreciated, thanks.
Australia Forum Administrator #1
Well that is pretty simple. Did you read up on regular expressions?

To do the first one:


local x = wait.match ("%-+ %a%d+ %-+", 5)


%a means a letter and %d+ means one or more numbers.

And since "-" has a special meaning, put a % before it.
Amended on Wed 10 Mar 2010 11:48 PM by Nick Gammon
#2
Alright great, thanks. And as for the end line (----------- 4:2:0 -----------), there can be any number of digits where each number is located, and there can be a "-" in front of each number. For example (----------- -44:-22:-00 -----------). Also, there can be a different amount of -'s before and after the numbers. It's the last piece to the puzzle :P.