regex_replace问题 [英] regex_replace issue
问题描述
我使用 C ++ 11 (Windows 7 64位,visual studio 2012)
用另一个子字符串替换一些子字符串。
我有一个文件,有一个双斜杠(//)分隔的数字。
例如:
10 // 20 // 1 3 // 4 // 5 5 // 2 / / 1到10 20 1 3 4 5 5 2 1
但是,当我尝试正则表达式,似乎我做错了。什么都没发生。此外,我在哪里可以阅读更多关于 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,);
$ b
但没有任何反应。
像我之前说的,如果你也可以指出一个网页,我可以更多地了解这个 / p>
regex_replace
不会对字符串进行就地编辑;
例如:
auto out = regex_replace(fData,r, );
在此示例中,out将是期望值的字符串(10 20 1 3 4 5 5 2 1 )。此备忘单非常实用(从http://cpprocks.com/regex-cheatsheet/ )。享受!
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
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!
这篇关于regex_replace问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!