samedi 15 août 2020

Is there a way to do multiple replacements simultaneously with C++ regex?

Is there is a way to do multiple replacements simultaneously? (for cases when the order of replacement matters in the final result)

e.g: If I wanted to change all characters A's to B's and all B's to C's, with only the original B's being converted, how can I get that?

I want ABC => BCC,

not ABC => CCC

s = regex_replace(s, regex("B"), "C");
s = regex_replace(s, regex("A"), "B");

this works because it is not cyclic... but what if I wanted to replace the C's for something that include A's or B's also?

Aucun commentaire:

Enregistrer un commentaire