
llwaeva@21cn.com 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.