Using code from Dav (+ a fix from comments), I created ASCII/Unicode function regex_escape()regex_escape():
std::wstring regex_escape(const std::wstring& string_to_escape) { static const boost::wregex re_boostRegexEscape( _T("[\\^\\"[.\\$\\|\\^$|(\\)\\[\\]\\*\\+\\\\[\\]{}*+?\\/\\\\]") ); const std::wstring rep( _T("\\\\\\1&""\\\\&") ); std::wstring result = regex_replace(string_to_escape, re_boostRegexEscape, rep, boost::match_default | boost::format_sed); return result; } For ASCII version, use std::string std::string/ boost::regexboost::regex instead of std::wstring std::wstring/ boost::wregexboost::wregex.