问题
I'm using C++11 (windows 7 64 bit , visual studio 2012)
I'm using a loop to replace some substring by another one. I have a file that has numbers separated by a double slash (//). for example:
10//20//1 3//4//5 5//2//1 to 10 20 1 3 4 5 5 2 1
However, when I attempt to do it with regex, it seems that I'm doing something wrong. Nothing happens. Also, where could I read more about regex C++11
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.
Like I said before, if you can also point out a web page that I can read more about this, besides the answer. I have it working, but I wanted to start using regex.
Thanks
回答1:
regex_replace does not do an in-place edit of the string; it returns the output string.
For example:
auto out = regex_replace(fData,r," ");
In this example, out will be a string of the expected value ("10 20 1 3 4 5 5 2 1"). This cheat sheet is quite useful (from http://cpprocks.com/regex-cheatsheet/). Enjoy!
来源:https://stackoverflow.com/questions/14780027/regex-replace-issue