title: Reassigning strings to a set list of values in an array
body: <p>I have a list in Lua which is fixed format (it's an input from somewhere else).</p>
  
  <p>E.g.</p>
  
  <pre><code>a = {"apple", "apple 1", "pear", "orange", "orange 3", "kiwi", "tomato"}
  </code></pre>
  
  <p>I also have a look up table where I want to normalise this set and send them to a code format. Note: anything containing apple, such as apple 1, apple 2 etc will be mapped to the same value as apple.</p>
  
  <p>E.g.</p>
  
  <pre><code>"apple" =&gt; "RD"
  "pear" =&gt; "GR"
  "orange" =&gt; "OG"
  "kiwi" =&gt; "GR"
  "tomato" =&gt; "RD"
  "banana" =&gt; "YL"
  etc...
  </code></pre>
  
  <p>I then want to return a list with all of these substitutions:</p>
  
  <pre><code>fruitBox = {"RD", "GR", "OG"}
  </code></pre>
  
  <p>I don't mind if <code>fruitBox</code> has repeated values or not, whatever is easiest, but it should only return values if they are represented in both the lookup and the original list. I have been trying to do this but matching the strings, but I always end up getting stuck with how to output the codes. I also tried <code>string.gsub</code> and iterating through a <code>for loop</code> but still got nowhere useful.</p>