Re: [boost] [regex] Escaping a search string?

2003-08-14 Thread John Maddock
>Given that I have a string 's' from somewhere, I'd like to create a
>regular expression where some part must match that string. The problem
>is, the 's' could contain characters that have a special meaning in
>regular expressions. Is there some support function that can provide an
>escaped version of 's'? Something that transforms "my.*string" into
>"my\.\*string"? If there isn't, would it be possible/easy to provide one?

Good question, no there isn't, but how about:

std::string escape_regex(const std::string& s)
{
static const std::regex e("[\\[\\]$\\^|.+*?(){}]");
return regex_merge(s, e, "$&");
}

Just off the top of my head and untried

I'll try and think up something more general that works with all the flag
settings though...

John.


___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] [regex] Escaping a search string?

2003-08-09 Thread George A. Heintzelman

> Given that I have a string 's' from somewhere, I'd like to create a 
> regular expression where some part must match that string. The problem 
> is, the 's' could contain characters that have a special meaning in 
> regular expressions. Is there some support function that can provide an 
> escaped version of 's'? Something that transforms "my.*string" into 
> "my\.\*string"? If there isn't, would it be possible/easy to provide one?

Second that request. I just had a need for this, though I wound up 
ignoring the problem rather than fixing it...

George Heintzelman
[EMAIL PROTECTED]


___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost