Boost logo

Boost Users :

From: Pavol Droba (droba_at_[hidden])
Date: 2007-03-15 05:37:47


Hi,

llwaeva_at_[hidden] wrote:
> 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?
>

The only solution that I can comeup with is to run replace_all_regex
twice. Once for #f pattern and the other time for the #g pattern.

If you use format_literal, it is obvious, that (?1 and (?2 format
specifiers are not evaluated.

Maybe there is another solution for this, but I don't know about it.

Best regards,
Pavol.


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