我有一个类似
的QString。QString qReplaceByText("**\\g<char>**");
如果我尝试将其转换为wstring,则将\替换为\\
std::wstring wReplaceByText = qReplaceByText.toStdWString()
;
qReplaceByText变为
**\\\\g<char>**
如何避免这种情况?
这是我的代码段
std::wstring searchText(L"(?P<char>.)(?P=char)");;
wsregex regExp;
std::wstring strOut;
try
{
regExp = wsregex::compile( searchText, boost::xpressive::icase );
std::wstring wsObjectName = L"tweet" ;
std::wstring wReplaceByText = qReplaceByText.toStdWString();
strOut.resize( wsObjectName.length() + wReplaceByText.length() );
std::wstring::iterator itOut = strOut.begin();
boost::xpressive::regex_replace(itOut, wsObjectName.begin() , wsObjectName.end(), regExp, wReplaceByText, regex_constants::format_perl );
}