Boost logo

Boost Users :

From: llwaeva_at_[hidden]
Date: 2007-03-15 04:22:54


Hi there,
  I found that the behavior of replace_all_regex is weird while specifing format flag as format_literal.
For example, I would like to replace %f and %g in a source with some
text respectively. The code is

string source = "#f = %f \r\n #g = %g \r\n";
string text1("<footi_at_[hidden]>");
string text2("""name""<name_at_email.101.pi>");

replace_regex(source, boost::regex("%f"), text1, boost::regex_constants::format_literal);
replace_regex(source, boost::regex("%g"), text2, boost::regex_constants::format_literal);

The result is fine. However, I would like to use replace_all_regex instead. i.e.

replace_all_regex( source, boost::regex("(%f|%g)"), string("(?1 loofon_at_[hidden])(?2 ""name""<name_at_email.101.pi>"), boost::regex_constants::format_literal);

However, because of format_literal, what I get is

#f = (?1 loofon_at_[hidden])(?2 "name"<name_at_email.101.pi>")
#g = (?1 loofon_at_[hidden])(?2 "name"<name_at_email.101.pi>")

rather than
#f = loofon_at_[hidden]
#g = "name"<name_at_email.101.pi>"

In my case, I need to handle a heap of patterns and using replace_all_regex is convenient. Any way to use both
replace_all_regex and format_literal without going into the trouble mentioned above?

Thanks in advance.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net