Boost logo

Boost Users :

Subject: Re: [Boost-users] [regex] function to escape regex control characterslike QRegExp::escape?
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2010-05-20 07:51:27


John Maddock wrote:
>> Is there a function to escape regex control characters like
>> RegExp::escape already in boost::regex or perhaps boost::expressive?
>
> No.... it depends upon the regular expression syntax as well, should be
> trivial to make a list of special characters and do a search and
> replace? Oh, and don't forget you can wrap the "literal" part of the
> expression in \Q ... \E which has the same effect.

Thanks John, I'm replacing the use of Qt's QRegExp with boost regex.
QRegExp::escape was used to ensure that when the user selects from a
list of single char delimiters, which has many of the regex control
characters, can be used to split a string. So in this case a simple
mapping function suffices.

Thanks for the \Q ... \E info as well.

Jeff


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