title: Create regular expression from string
body: <p>Is there any way to create the regex <code>/func:\[sync\] displayPTS/</code> from string <code>func:[sync] displayPTS</code>?</p>
  
  <p>The story behind this question is that I have serval string pattens to search against in a text file and I don't want to write the same thing again and again.</p>
  
  <pre><code> File.open($f).readlines.reject {|l| not l =~ /"#{string1}"/}
   File.open($f).readlines.reject {|l| not l =~ /"#{string2}"/}
  </code></pre>
  
  <p>Instead , I want to have a function to do the job:</p>
  
  <pre><code>  def filter string
            #build the reg pattern from string
            File.open($f).readlines.reject {|l| not l =~ pattern}
    end
    filter string1
    filter string2
  </code></pre>