SHARE
TWEET

better match

a guest Apr 21st, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function match(name,query)
  2.     local spaced_name = name:gsub("_"," "):gsub("([^%u%s])(%u)%f[%l%d]","%1 %2"):lower()
  3.     local changed_query = "^"..query:gsub("_"," "):gsub("%*","@"):gsub("%.","~"):gsub(
  4.         "[%l%d%u]",
  5.         function(letter)
  6.             if letter:match"%u" then
  7.                 return ' '..letter:lower().."%S*"
  8.             else
  9.                 return letter..".*"
  10.             end
  11.         end):gsub("^ ",""):gsub("%s+"," "):gsub("@","%%S+"):gsub("~",".*")
  12.     return spaced_name:match(changed_query),spaced_name,changed_query
  13. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top