Ben Hutchings
Arno Schäfer wrote:
Hi all,
Using "regex_replace(string, pattern, replace_string, flags)" I got some unwished results. I can't find out what flag set I have to use, that the replacement string was taken, as it is. <snip>
Post your code.
Ben.
Here is my test case: <snip> #include <iostream> #define BOOST_NO_WREGEX #include "boost/regex.hpp" using namespace std; using namespace boost; int main(int argc, char *argv[], char *envp[]) { string source_org("My path: '#PATH#'"); regex pattern("#PATH#"); string replace("D:\\temp\\rest"); source_org += " " + source_org; bool only_first = false; while ( true ) { string source(source_org); regex_constants::match_flag_type flags = regex_constants::match_default; if ( only_first ) flags |= regex_constants::format_first_only; string result = regex_replace(source, pattern, replace, flags); cout << "Pattern \"" << pattern.expression() << "\" in string \"" << source << "\" should be replaced with \"" << replace << "\"" << endl << "\"" << result << "\"" << endl << endl; if ( only_first ) break; only_first = !only_first; } return 0; } Ouput: Pattern "#PATH#" in string "My path: '#PATH#' My path: '#PATH#'" should be replaced with "D:\temp\rest" est'"My path: 'D: emp Pattern "#PATH#" in string "My path: '#PATH#' My path: '#PATH#'" should be replaced with "D:\temp\rest" est' My path: '#PATH#'" Exspected output: Pattern "#PATH#" in string "My path: '#PATH#' My path: '#PATH#'" should be replaced with "D:\temp\rest" "My path: 'D:\temp\rest' My path: 'D:\temp\rest'" Pattern "#PATH#" in string "My path: '#PATH#' My path: '#PATH#'" should be replaced with "D:\temp\rest" "My path: 'D:\temp\rest' My path: '#PATH#'" <snip> Arno