|
Boost Users : |
From: llwaeva_at_[hidden]
Date: 2007-03-13 11:35:41
hi there,
I am working with a pattern-replace job with boost:regex. For
convenience, I use replace_all_regex to do that. Here is my code
replace_all_regex( TEXT_TO_BE_REPLACED, regex_exp, format_string, format_all );
TEXT_TO_BE_REPLACED is a text containing some patterns like %a, %b and %c which will be repalced with a specific
string(format_string) that is inputed by user. However, the input string (format_string) may have some characters related
to the regular expression, such characters must be escaped before the substitution. The following code is for that
purpose
replace_all( input, "$", "$$" );
replace_all( input, "\\", "\\\\" );
replace_all( input, ":", "\\:" );
replace_all( input, "?", "\\?" );
replace_all( input, "(", "\\(" );
replace_all( input, ")", "\\)" );
The substitution works fine sometimes and fails when the input string (format_string) contains character which is not
escaped. I just wonder if there is any function defined in boost::regex to escape all SPECIAL characters.
Thanks in advance.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net