0

If I have a search box and want to find if a string contains certain words (not case sensitive) and/or numbers.

search = "Brown lazy 46"
textline = "The quick brown fox jumped over 46 lazy dogs"
if string.match(textline, search) then
  result = textline
end

just like a web search.

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
LuaStart
  • 397
  • 2
  • 11

1 Answers1

1
search = "Brown lazy 46"
textline = "The quick brown fox jumped over 46 lazy dogs"

for item in string.gmatch(search, "%S+") do 
if string.find(textline, string.lower(item)) then
   result = textline
    end
end

You break up the word values ​​you are looking for and convert them into an array. Then you should loop that array and check if your main variable is in it.

If I understood correctly what you want to do this should solve your problem.

  • I just had to change it all to lowercase it to work "if string.find(string.lower(textline), string.lower(item)) then" – LuaStart Dec 18 '21 at 21:13