ScriptUO
Official ScriptUO EasyUO Scripts => Script Debug => Topic started 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:
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
--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.
-
Problem solved
if line:lower():match('^'..v..'[ (]*') or line:lower():match('[ ]+'..v..'[ (]*') then