Jan Laloux
Jan Laloux

Reputation: 249

Regex VS13: replace backslash

I want to replace a \ in a string with \\\\:

wsmatch Matches;
wstring String = L"\\";
regex_match( String, Matches, wregex( L"(\\\\)" ) );
if( Matches.size() > 0 ){
    regex_replace( String, wregex( L"(\\\\)" ), L"x" );
    wcout << L"Replaced in: " << String << endl;
}

It results in the following output:

Replaced in: \

It seems like a bug in VS13 or am I missing something?

Upvotes: 2

Views: 193

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627087

Strings are immutable, use

String = regex_replace( String, wregex( L"(\\\\)" ), L"x" );

enter image description here

Upvotes: 1

Related Questions