title: Verbatim-like context in a regular expression
body: <p><strong>Question:</strong></p>
  
  <p>Is there any way to tell a regular expression engine to treat a certain part of a regular expression as <em>verbatim</em> (i.e. look for that part exactly as it is, without the usual parsing) without manually escaping special characters?</p>
  
  <p><strong>Some context:</strong></p>
  
  <p>I'm trying to backreference a group on a given regular expression from another regular expression. For instance, suppose I want to match <code>hello(.*?)olleh</code> against text 1 and then look for <code>bye$1eyb</code> in text 2, where <code>$1</code> will be replaced by whatever matched group 1 in text 1. Therefore, if text 1 happens to contain the string <code>"helloFOOolleh"</code>, the program will look for <code>"byeFOOeyb"</code> in text 2.</p>
  
  <p>The above works fine in most cases, but if text 1 were to contain something like <code>"hello.olleh"</code>, the program will match not only <code>"hello.olleh"</code> but also <code>"helloXolleh"</code>, <code>"hellouolleh"</code>, etc. in text 2, as it is interpreting <code>.</code> as a regex special character and not the plain dot character.</p>
  
  <p><strong>Additional comments:</strong></p>
  
  <p>I can't just search for the plain string resulting from parsing <code>$1</code> into whatever group 1 matches, as whatever I want to search for in text 2 could itself contain other unrelated regular expressions.</p>
  
  <p>I have been trying to avoid parsing the match returned from text 1 and escape every single special character, but if anyone knows of a way to do that neatly that could also work.</p>
  
  <p>I'm currently working on this in Python, but if it can be done easily with any other language/program I'm happy to give it a try.</p>