【发布时间】:2011-07-27 14:57:38
【问题描述】:
转义任意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);
}
【问题讨论】: