ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: KaliOfLS on January 17, 2013, 07:05:00 PM

Title: Regex Question
Post by: KaliOfLS on January 17, 2013, 07:05:00 PM
Okay, tossing together something to warm my heart up to regex.. if possible.

Consider these lines:

Code: [Select]
if this then
elseif this then
else end

if breif then
end

function t()
end

local t = function()
end
Let's consider something like this
Code: [Select]
--Lets assume I've opened the file, and will iterate with f:lines()
local sfind = {'if','end','function'}
for line in f:lines() do
   for _,v in pairs(sfind) do
        if line:match(sfind) do
       --I am trying to find and pair if/end counts.  so I'd like to only find 'if', not elseif or words containing if.  this fails.
        end
       if line:match('[ ]*'..sfind)
       --again fails  because I'm not forcing a space.     
       end
       if line:match('[ ]+'..sfind)
       --fails because I have no spaces in front of some lines
       end
   end
end

brutal, I'm sure I've tried others, but can't remember all of them.  I need like a
if nothing OR ( any number of spaces AND no characters) OR ( if any character then require space ) then match token sfind.
Title: Re: Regex Question
Post by: KaliOfLS on January 17, 2013, 09:07:22 PM
Problem solved
if line:lower():match('^'..v..'[ (]*') or line:lower():match('[ ]+'..v..'[ (]*') then