regex_replace issue

不羁的心 提交于 2020-01-11 09:12:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!