From: Ross Smith (rosss_at_[hidden])
Date: 2003-08-07 17:04:58
George A. Heintzelman wrote:
>>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...
There must be something in the air; I just had a need for this too. My
quick-and-dirty solution was to simply replace every non-alphanumeric
character with a hex escape sequence (\xNN).
Having it just add escapes to a list of special characters wouldn't work
as a general solution, because the list of characters depends on the
flags passed to the regex functions. Of course there are settings where
my hex-escape solution won't work either. I don't think a general
solution is possible without making it part of the library; it needs
access to the innards of the regex objects in order to know the exact
syntax they recognise.
-- Ross Smith ...................... Pharos Systems, Auckland, New Zealand "Remember when we told you there was no future? Well, this is it." -- Blank Reg
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk