fork download
  1. import re
  2.  
  3. keys = [
  4. "name",
  5. "anotherkey"
  6. ]
  7. r = r"['\"](" + "|".join([re.escape(key) for key in keys]) + r")['\"]\s*=\s*(?:'([^']*)'|\"([^\"]*)\")"
  8. s = "atable['akeyofthetable'] = { 'name' = 'a name',\n\t 'thevalue' = 34, \n\t \"anotherkey\" = 'something' }"
  9.  
  10. print(re.findall(r,s))
Success #stdin #stdout 0.04s 9436KB
stdin
Standard input is empty
stdout
[('name', 'a name', ''), ('anotherkey', 'something', '')]