The problem with regex_replace
I am using C ++ 11 (Windows 7 64 bit, visual studio 2012)
I am using a loop to replace some substring with another. I have a file that has numbers separated by double slashes (//). eg:
10//20//1 3//4//5 5//2//1 to 10 20 1 3 4 5 5 2 1
However, when I try to do it with a regex , it seems like I am doing something wrong. Nothing happened. Also, where could I find out more about C ++ 11 regex
string fData(data.substr(2));
string replaceStr("10//20//1 3//4//5 5//2//1");
regex r("//"
regex_replace(fData,r," ");
but nothing happens.
As I said, if you can also specify a webpage I can read about it besides the answer. It works for me, but I wanted to start using regex.
thank
source to share
regex_replace
does not edit the line in place; it returns a string of output.
For example:
auto out = regex_replace(fData,r," ");
In this example, out will be the string of the expected value ("10 20 1 3 4 5 5 2 1"). This cheat sheet is quite helpful (from http://cpprocks.com/regex-cheatsheet/ ). Enjoy!
source to share