title: Pass a string into regex
body: <p>Consider the following:</p>
  
  <pre><code> function filterFoods() {
     var foods = [
        {food: 'Bacon'}, {food: 'Butter'}, {food: 'Chicken'}, {food: 'Cocoa butter'},
        {food: 'Saussages'}, {food: 'Ham'}, {food: 'Duck'}, {food: 'Salmon'},
        {food: 'Fish'}, {food: 'Lamb'}, {food: 'Fries'}, {food: 'Tomatoes'},
        {food: 'Chicken'}, {food: 'Carrot'}, {food: 'Egg'}, {food: 'Avocado'},
        {food: 'Duck'}, {food: 'Hello'}, {food: 'Cheese'}, {food: 'Carrot'},
        {food: 'Potato'}, {food: 'Sweet Potato'}, {food: 'Pineapple'}, {food: 'Peanut'},
    ]
    return foods.filter(function(food) {
      return (/po/gi).test(food.food);
    });
  }
  
  console.log(
    filterFoods()
  )
  </code></pre>
  
  <p><a href="http://jsbin.com/gudekaruha/edit?js,console,output" rel="nofollow">http://jsbin.com/gudekaruha/edit?js,console,output</a></p>
  
  <p>I'm getting back <code>[{food: 'Potato'},{food: 'Sweet Potato'}]</code>, which is what I want.</p>
  
  <p>But I want to be able to pass something into the filterFoods function, and then into the regex, kind of like this:</p>
  
  <pre><code> function filterFoods(query) {
     var foods = [
        {food: 'Bacon'}, {food: 'Butter'}, {food: 'Chicken'}, {food: 'Cocoa butter'},
        {food: 'Saussages'}, {food: 'Ham'}, {food: 'Duck'}, {food: 'Salmon'},
        {food: 'Fish'}, {food: 'Lamb'}, {food: 'Fries'}, {food: 'Tomatoes'},
        {food: 'Chicken'}, {food: 'Carrot'}, {food: 'Egg'}, {food: 'Avocado'},
        {food: 'Duck'}, {food: 'Hello'}, {food: 'Cheese'}, {food: 'Carrot'},
        {food: 'Potato'}, {food: 'Sweet Potato'}, {food: 'Pineapple'}, {food: 'Peanut'},
    ]
    return foods.filter(function(food) {
      return (/query/gi).test(food.food);
    });
  }
  
  console.log(
  filterFoods('po')
  )
  </code></pre>
  
  <p>But I'm getting back an empty array. Now correct me if I'm wrong but I think it's because I'm passing it in as a string, so how do I achieve this?</p>
  
  <p>Thanks in advance</p>