title: Javascript adding variable to a regular expression
body: <p>I've written the following function in Typescript:</p>
  
  
  
  <pre><code>public searchPosts(keyword ? : string): Post[] {
    return this._posts.filter(function(post) {
      if (post.title.search(new RegExp('money', 'gi')) &gt;= 0) {
        return post;
      }
    });
  }
  </code></pre>
  
  <p>It's working just fine but, I need to make it a little dynamic so that instead of hardcoded value i.e. money, I can put my keyword variable in RegExp (<code>new RegExp(keyword, 'gi')</code>). But doing so does not return anything even for 'money' as a keyword. </p>
  
  <p>Any ideas on what I'm doing wrong here? </p>