Numbered trackback followed by a literal number

I am trying to replace a regex. The specific problem that I cannot understand is that, following my 2nd inverse representation, I have a string literal (number one). Using MS Visual Studio 2012 (C ++ console project ... not .NET), it does not work. I guess because it takes my backreference as $ 21, instead of $ 2. I tried a different syntax but can't come up with something that works!

std::string input = "my_variable_name_iei_lo1";
std::string regx = "(\\w+)iei_(lo_hi)1";
std::string sub = "$1ied_$21";

std::regex rx(regx);

std::string result = std::regex_replace(input, rx, sub);

// result is "my_variable_name_ied_"
// should be "my_variable_name_ied_lo1"

I tried various methods of setting a backlink:

std::string sub = "$1ied_${2}1";

// result is "my_variable_name_ied_${2}1"
// should be "my_variable_name_ied_lo1"

Other things give me syntax errors, including trying to use named capture groups, but then read that this is no longer supported. So close to my answer, but still so far away!

+4
1

Gunn:

Using $021 worked! I knew about the two digit limitation (99 capture groups)
but for whatever reason, never thought to try 01, 02, etc. So having the substitution
string be "$01ied_$021" gives me the result I was looking for. Thanks!
0

All Articles