title: Is it safe to read regular expressions from a file?
body: <p>Assuming a Perl script that allows users to specify several text filter expressions in a config file, is there a safe way to let them enter regular expressions as well, without the possibility of unintended side effects or code execution? Without actually parsing the regexes and checking them for problematic constructs, that is. There won't be any substitution, only matching.</p>
  
  <p>As an aside, is there a way to test if the specified regex is valid before actually using it? I'd like to issue warnings if something like <code>/foo (bar/</code> was entered.</p>
  
  <p>Thanks, Z.</p>
  
  <p><hr>
  EDIT:<br>
  Thanks for the very interesting answers. I've since found out that the following dangerous constructs will only be evaluated in regexes if the <code>use re 'eval'</code> pragma is used:</p>
  
  <pre><code>(?{code})
  (??{code})
  ${code}
  @{code}
  </code></pre>
  
  <p>The default is <code>no re 'eval'</code>; so unless I'm missing something, it should be safe to read regular expressions from a file, with the only check being the eval/catch posted by Axeman. At least I haven't been able to hide anything evil in them in my tests.</p>
  
  <p>Thanks again. Z.</p>