I'm currently working on a script gathering information from a website. I'm wondering if string.match would be able to accept regex pattern matching, such as the following:
string.match(page, "(?:(Phrase One|Phrase Two|Phrase Three|...))")
The problem is, I don't know if it can be done, but I'm willing to try any solutions. Thanks!
You can use the Lrexlib if you need full blown regular expressions.
What you could do is to define a function which takes your patterns as a table and then returns a table of matches, or if you only need to know if the text is contained in the page then following would work.
function FindAny(strContent,tblPatterns)
bReturn = false
for i,strPattern in ipairs(tblPatterns) do
if (string.find(strContent,strPattern) ~= nil) then
bReturn = true
break
end
end
return bReturn
end
if FindAny('pattern 4',{'pattern 1','pattern 2','pattern 3','pattern 4'}) then
print('Pattern Found')
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With