Replace substring using regex with condition
문제
I need to replace every substring in a string that matches a regex, something like this:
std::string result = boost::regex_replace("my# random *#string ##"
, boost::regex("#([^#*]*[*][^#*]*)#")
, tr);
std::string tr(const boost::smatch &m)
{
std::string replaceString;
bool ret = CheckIfWeNeedToReplace(m[0], replaceString);
if (ret)
return replaceString; // replacing
else
return m[0]; // remain the same
}
e.g. for string "my# random *#string ##"
there is one match for regex "#([^#*]*[*][^#*]*)#"
, that is " random *"
, and if CheckIfWeNeedToReplace
return false, then the string remain the same, if not - it will be something like this "my#NEW SUBSTRING#string ##"
My code doesn't work, what did I do wrong ?
올바른 솔루션이 없습니다
제휴하지 않습니다 StackOverflow