私は次の機能を持っています(それは機能します):
boost::regex ex(REGEX_TAG);
boost::match_results<std::string::const_iterator> extend;
std::string::const_iterator start, end;
boost::match_flag_type flags;
std::string value("");
start = input.begin();
end = input.end();
flags = boost::match_default;
// The question start here
while (boost::regex_search(start, end, extend, ex, flags))
{
try
{
value = boost::any_cast<std::string>(param.at(extend[1]));
}
catch (const boost::bad_any_cast& err) {}
catch (const std::out_of_range& err){}
input = boost::regex_replace(input, ex, value, boost::match_default | boost::format_first_only);
value.clear();
start = extend[0].second;
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
しかし、私は実際には2つの正規表現関数を使用していますが、それらは多くの同様のことを行うと思います(式を見つける...)。boost::regex_search
を削除して同じ出力を得るという考えはありますか
編集:
私はdjangoのテンプレートファイルを解析しようとしています:
入力:{{ lastName }} : {{ firstName }}
param は文字列のマップ、boost::any const std::map<std::string, boost::any>&
と REGEX_TAG: #define REGEX_TAG "\\{\\{ ([a-zA-Z0-9_-]+) \\}\\}"
それは機能しています、私はそれも検索しているboost::regex_search
ので削除できるかどうか尋ねているだけです(私は推測します)boost::regex_replace