title: How to convert string to regex literal
body: <p>What's the best way to escape an arbitrary <code>std::wstring</code> for use inside a regular expression? For example, convert <code>you owe me $</code> to <code>you owe me \$</code>?</p>
  
  <p>My scenario: I want to use a <code>std::tr1::wregex</code> to search for a whole word. So I want to do something like:</p>
  
  <pre><code>std::wstring RegexEscape(const std::wstring&amp; inp)
  {
      return ?????
  }
  
  bool ContainsWholeWord(const std::wstring&amp; phrase, const std::wstring&amp; word)
  {
      std::tr1::wregex regex(std::wstring(L"\\b") + RegexEscape(word) + L"\\b");
      return std::tr1::regex_match(phrase, regex);
  }
  </code></pre>