fork download
  1. function mymatch(str)
  2. local _, _, ok, oreveal = str:find("^(ok%f[%A]);?(.*)$")
  3. if ok == nil then
  4. _, _, ok, oreveal = str:find("^(cancel%f[%A]);?(.*)$")
  5. end
  6. if oreveal == "" then
  7. oreveal = nil
  8. end
  9. return ok, oreveal
  10. end
  11.  
  12. -- this is what I want
  13. print(mymatch("ok")) -- ok nil
  14. print(mymatch("cancel")) -- cancel nil
  15. print(mymatch("ok;domatch")) -- ok domatch
  16. print(mymatch("okdontmatch")) -- nil nil
Success #stdin #stdout 0.01s 5512KB
stdin
Standard input is empty
stdout
ok	nil
cancel	nil
ok	domatch
nil	nil