[Q] regular expressions change the 'substitue with' value
Looking for some help with how to use regular expression library I have a string "!1!" I am replacing it with "\temp\i\otrq92rq40100__db1003.xls" ( a windows path to a file) This is how I am doing it std::string repl=subst_designator+ boost::lexical_caststd::string(counter)+ subst_designator; boost::algorithm::replace_all_regex(new_arg, boost::regex(repl),*res_it); Where: subst_designator = '!' counter = 1 new_arg = "!1!" *res_it="\temp\i\otrq92rq40100__db1003.xls" after the above code, the new_arg contains a strange string that appears to have back slashes removed and the first \t replaced with something like a 'tab' new_arg=" empiotrq92rq40100__db1003.xls" I am thinking that this is wrong, because the regular expression should copy without modifications the value of *res_it into the new_arg I am using 1.38 on windows with VS9. My question is , how can make it so the string in *res_it substitutes !1! thank you in advance, Vlad -- Vlad P author of C++ ORM http://github.com/vladp/CppOrm/tree/master -- http://www.fastmail.fm - IMAP accessible web-mail
AMDG V S P wrote:
Looking for some help with how to use regular expression library
I have
a string
"!1!"
I am replacing it with
"\temp\i\otrq92rq40100__db1003.xls"
( a windows path to a file)
This is how I am doing it
std::string repl=subst_designator+ boost::lexical_caststd::string(counter)+ subst_designator;
boost::algorithm::replace_all_regex(new_arg, boost::regex(repl),*res_it);
Where:
subst_designator = '!' counter = 1 new_arg = "!1!" *res_it="\temp\i\otrq92rq40100__db1003.xls"
after the above code, the new_arg contains a strange string that appears to have back slashes removed and the first \t replaced with something like a 'tab' new_arg=" empiotrq92rq40100__db1003.xls"
I am thinking that this is wrong, because the regular expression should copy without modifications the value of *res_it into the new_arg
I am using 1.38 on windows with VS9.
My question is , how can make it so the string in *res_it substitutes !1!
With replace_all_regex, the string is not substituted literally. Can't you use replace_all instead of replace_all_regex? If you really need the search to use a regex, you can use find_format_all with regex_finder and const_formatter. In Christ, Steven Watanabe
Thank you, replace_all forks for me now. But probably will need to go back to regular expression in the future. I do not think I need to search, I just need to replace (in-place) I assume the find_XXX functions do not do that. I might have misunderstood but if I have a string " something!1!else!1!ornot " and I want to replace !1! with a new replacement text "c:\temp\file.xls", isn't the replace_all_regex the correct function to use? if not, can you suggest an example with the combination of functions you have mentioned -------- thank you
With replace_all_regex, the string is not substituted literally. Can't you use replace_all instead of replace_all_regex? If you really need the search to use a regex, you can use find_format_all with regex_finder and const_formatter.
In Christ, Steven Watanabe
-- Vlad P author of C++ ORM http://github.com/vladp/CppOrm/tree/master -- http://www.fastmail.fm - mmm... Fastmail...
AMDG V S P wrote:
Thank you, replace_all forks for me now.
But probably will need to go back to regular expression in the future.
I do not think I need to search, I just need to replace (in-place) I assume the find_XXX functions do not do that.
I might have misunderstood but if I have a string
" something!1!else!1!ornot "
and I want to replace !1! with
a new replacement text "c:\temp\file.xls",
isn't the replace_all_regex the correct function to use?
No. replace_all_regex uses regex_formatter which is too fancy because the format strings behave as described in http://www.boost.org/libs/regex/doc/html/boost_regex/format.html
if not, can you suggest an example with the combination of functions you have mentioned
boost::find_format_all(s, boost::regex_finder("!1!"), boost::const_formatter("c:\temp\file.xls")) In Christ, Steven Watanabe
On Fri, Jun 26, 2009 at 5:54 PM, Steven Watanabe
/* snip thread */
Out of curiosity, but this is C++, and is not a backslash in a string in C++ an escape character, hence things like "\temp\i\otrq92rq40100__db1003.xls" should actually be "\\temp\\i\\otrq92rq40100__db1003.xls", and since "\temp\i\otrq92rq40100__db1003.xls" was turning into "empiotrq92rq40100__db1003.xls", is that not correct since the backslashes were not escaped? Hence, this problem has *nothing* to do with Boost and everything to do with forgetting to escape the escape character? :)
i do no think so,
because escapes are only needed for strings
in source files not the ones in memory
in this particular instance the string came back from
a call to a remote corba service
and when you print it out to stdout it had the slashes.
On Sun, 12 Jul 2009 17:07 -0600, "OvermindDL1"
On Fri, Jun 26, 2009 at 5:54 PM, Steven Watanabe
wrote: /* snip thread */
Out of curiosity, but this is C++, and is not a backslash in a string in C++ an escape character, hence things like "\temp\i\otrq92rq40100__db1003.xls" should actually be "\\temp\\i\\otrq92rq40100__db1003.xls", and since "\temp\i\otrq92rq40100__db1003.xls" was turning into "empiotrq92rq40100__db1003.xls", is that not correct since the backslashes were not escaped? Hence, this problem has *nothing* to do with Boost and everything to do with forgetting to escape the escape character? :) _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- Vlad P author of C++ ORM http://github.com/vladp/CppOrm/tree/master
-- http://www.fastmail.fm - The way an email service should be
On Mon, Jul 13, 2009 at 1:25 AM, V S P
i do no think so, because escapes are only needed for strings in source files not the ones in memory
in this particular instance the string came back from a call to a remote corba service and when you print it out to stdout it had the slashes.
Ah, did not get that impression from what you posted, this looks like C/C++ to me:
subst_designator = '!' counter = 1 new_arg = "!1!" *res_it="\temp\i\otrq92rq40100__db1003.xls" Meaning the last line would be the cause of the problems and would cause empiotrq92rq40100__db1003.xls to be emitted just like what you said that you saw.
I just copied the data from the debugger and
put it like it is assigned to variables so that
I could show the issue I am having :-)
Which got resolved by Steve W.
On Mon, 13 Jul 2009 12:00 -0600, "OvermindDL1"
On Mon, Jul 13, 2009 at 1:25 AM, V S P
wrote: i do no think so, because escapes are only needed for strings in source files not the ones in memory
in this particular instance the string came back from a call to a remote corba service and when you print it out to stdout it had the slashes.
Ah, did not get that impression from what you posted, this looks like C/C++ to me:
subst_designator = '!' counter = 1 new_arg = "!1!" *res_it="\temp\i\otrq92rq40100__db1003.xls" Meaning the last line would be the cause of the problems and would cause empiotrq92rq40100__db1003.xls to be emitted just like what you said that you saw.
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- Vlad P author of C++ ORM http://github.com/vladp/CppOrm/tree/master
-- http://www.fastmail.fm - A no graphics, no pop-ups email service
participants (3)
-
OvermindDL1
-
Steven Watanabe
-
V S P