28 Jul
2006
28 Jul
'06
9:02 a.m.
llwaeva@21cn.com wrote:
Hi there, I am using regex_replace to find_replace a pattern. The code is shown below
string src = "xxx%R__xy\r\n%\r\nRyyyy% A__%%A\r\n%Rzzz%C%Appp_%C0123\r\n%Rooo"; re = "(%R)|(%A)|(%C)"; format = "(?1#R)(?2#A)(?3#C)"; cout << "SOURCE:" << endl << src << endl << endl; regex_replace( src.begin(), src.begin(), src.end(), re, format, format_all ); cout << "OUTPUT:" << endl << src << endl << endl;
OK I've just realise what you're doing, and in short DON'T DO THAT!!!! regex_replace does not do inplace search and replace, YOU ABSOLUTELY CANNOT OVERWRITE A STRING YOU'RE STILL READING FROM! Use: src = regex_replace(src, re, format, format_all); instead. John.