title: c++11/regex - search for exact string, escape
body: <p>Say you have a string which is provided by the user. It can contain any kind of character. Examples are:</p>
  
  <pre><code>std::string s1{"hello world");
  std::string s1{".*");
  std::string s1{"*{}97(}{.}}\\testing___just a --%#$%# literal%$#%^"};
  ...
  </code></pre>
  
  <p>Now I want to search in some text for occurrences of <code>&gt;&gt;</code> followed by the input string <code>s1</code> followed by <code>&lt;&lt;</code>. For this, I have the following code:</p>
  
  <pre><code>std::string input; // the input text
  std::regex regex{"&gt;&gt; " + s1 + " &lt;&lt;"};
  
  if (std::regex_match(input, regex)) {
       // add logic here
  }
  </code></pre>
  
  <p>This works fine if <code>s1</code> did not contain any special characters. However, if <code>s1</code> had some special characters, which are recognized by the regex engine, it doesn't work.</p>
  
  <p>How can I escape <code>s1</code> such that <code>std::regex</code> considers it as a literal, and therefore does not interpret <code>s1</code>? In other words, the regex should be:</p>
  
  <pre><code>std::regex regex{"&gt;&gt; " + ESCAPE(s1) + " &lt;&lt;"};
  </code></pre>
  
  <p>Is there a function like <code>ESCAPE()</code> in <code>std</code>?</p>
  
  <p><strong>important</strong> I simplified my question. In my real case, the regex is much more complex. As I am only having troubles with the fact the <code>s1</code> is interpreted, I left these details out.</p>