如何最好地转义任意std::wstring
以在正则表达式中使用?例如,将you owe me $
转换为you owe me \$
?
我的情况是:我想使用std::tr1::wregex
搜索整个单词。所以我想做这样的事情:
std::wstring RegexEscape(const std::wstring& inp)
{
return ?????
}
bool ContainsWholeWord(const std::wstring& phrase, const std::wstring& word)
{
std::tr1::wregex regex(std::wstring(L"\\b") + RegexEscape(word) + L"\\b");
return std::tr1::regex_match(phrase, regex);
}