Boost logo

Boost :

Subject: Re: [boost] [regex] embed string/char in regex w/o escaping?
From: Yechezkel Mett (ymett.on.boost_at_[hidden])
Date: 2011-03-06 06:16:56


On Wed, Mar 2, 2011 at 5:43 PM, Jim Bell <Jim_at_[hidden]> wrote:
> On 1:59 PM, John Maddock wrote:
>>> To your point of escaping a string wrong, I fiddled with a
>>> regex_replace() that would remove all '\E' (end-of-quoted-sequence),
>>> including '\\\E', but not touch '\\E' (i.e., even numbers of '\'
>>> prefixing), and couldn't get it.
>>
>> I'm not sure I understand what you're trying to achieve there, can you
>> explain?
>>
>
> I was going for different form, but (hopefully) same result as yours:
>
> std::string my_escaped_string = "\\Q" + regex_replace(my_string, e,
> "\\\\$&") + "\\E";

I use something like

"\\Q" + boost::replace_all_copy(text, "\\E", "\\E\\\\E\\Q") + "\\E"

Yechezkel Mett


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk