Boost logo

Boost Users :

Subject: Re: [Boost-users] [Q] regular expressions change the 'substitue with' value
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-26 17:59:24


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_cast<std::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


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