mercredi 22 avril 2015

C++11 regex_replace group name separation

My regex_replace expression uses group $1 right before a '0' character in the replacement string like so:

#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main() {
    regex regex_a( "(.*)bar(.*)" );
    cout << regex_replace( "foobar0x1", regex_a, "$10xNUM" ) << endl;
    cout << regex_replace( "foobar0x1", regex_a, "$1 0xNUM" ) << endl;
}

The output is:

xNUM
foo 0xNUM

I'm trying to get output foo0xNUM without the middle whitespace.

How do I guard the group name $1 from the next character in the substitution string?

Aucun commentaire:

Enregistrer un commentaire