greenage
greenage

Reputation: 397

Lua - Nested if statements

I'm looking to check the validity of multiple filenames within a folder using LUA.

I can get the filenames passed through as variables (defined as a.message) and I need the script to run through all the regex patterns, and if it does not match any of them, then print "We need an alarm".

a = alarm.get ("GF91908920-49330")

   if regexp (a.message,"/CCF_[0-9]{6}_[0-9]{2}.csv/") then 

     if regexp (a.message,"/Issues_[0-9]{4}-[0-9]{2}-[0-9]{2}.csv/") then

        if regexp (a.message,"/POL_Operator_[0-9]{6}_[0-9]{2}.csv/") then 

        else print ("We need an alarm - ", a.message)

end
end
end

So, if variable matches one of the regex patterns, great, then end. If not, move on and check for a match against any of the other patterns, again, ending if a match is found.

If no matches are found amongst any of the regex then print "We need an alarm".

I hope that's clear enough.

Thanks.

Upvotes: 0

Views: 203

Answers (1)

Aki
Aki

Reputation: 2928

What you described is logical disjunction or so called OR. See Wikipedia article and Programming in Lua 3.3.

a = alarm.get("GF91908920-49330")

if regexp(a.message, "/CCF_[0-9]{6}_[0-9]{2}.csv/") or
   regexp(a.message, "/Issues_[0-9]{4}-[0-9]{2}-[0-9]{2}.csv/") or
   regexp(a.message, "/POL_Operator_[0-9]{6}_[0-9]{2}.csv/") then
       -- do something
else
   print("We need an alarm - ", a.message)
end

Assuming you actually have regexp implemented then that's it. If no, in Lua there are patterns available. You can read about them in Programming in Lua 20.2.

I highly recommend learning basics and doing at least minimal amount of research before you ask a question. Programming in Lua is available online and it is a great way to start with Lua.

Upvotes: 4

Related Questions