Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2006-07-28 05:08:35


llwaeva_at_[hidden] wrote:
> Here, expK found all the substring matching %K{xxx} (not including
> double % case). But the program didn't give
> me what I want, I guess the problem is from the expression where {
> and } is not expressed correctly. However, I
> didn't found how to express { and } in the document. Here is my
> guess of the correct form, tell me if it is
> correct or not
>
> 1) boost::regex expK("[^%]*%K\{([^\r\n])\}"); // here \{ represents
> { and \} represents } 2) boost::regex
> expK("[^%]*%K[{]{1}([^\r\n])[}]{1}"); // use [{]{1} and [}]{1} to
> limit the { and } occur once exactly 3) boost::regex
> expK("[^%]*%K\\{([^\r\n])\\}"); // here \\{ represents { and \\}
> represents }
>
> which one is correct? or all is wrong?

{ and } are repetition operators in regexes, if you want to match a literal
{ or } you can use either [{] or \{, the latter when embedded in a C++
string becomes "\\{" since the compiler processes the first \ before the
regex engine gets to see it.

John.


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