lundi 3 avril 2017

std::regex_replace: access index of disjunct match groups

I've been tasked with replacing boost::regex with std::regex and hit an issue with boost::regex references to capture group indexes.

The regex looks like that:

re = "(^Match1$)|(^Match2$)|(^Match3$)|(^Match4$)"

With a replace string:

replace_str = "(?{1}M1)(?{2}M2)(?{3}M3)(?{4}M4)"

If I call boost::regex_replace("Match1", re, replace_str, format_all) i get "M1" as result and with std::regex_replace("Match1", re, replace_str) the result consists of the whole replace_str.

The standardized variant of regex does not have the format_all option (not sure if that is the issue). http://ift.tt/1MXKGyq

How do I reproduce a similar behaviour with the c++11/14 regex library? Have I missed an option or syntax that does allow to use that behaviour without boost?

Aucun commentaire:

Enregistrer un commentaire