0

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.

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had a feeling I'd got the terminology wrong, another lesson learnt! Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.