Wednesday, April 6, 2011

Isn't it possible to use 'Repeats' in the lookaheads for boost:regex?

I'm trying to extract some variables in my C++ code nested in blocks
for example, if I have

  DEL_TYPE_NONE,
   DEL_TYPE_DONE,
 DEL_TYPE_WAIT,

I'd like to match
"DEL_TYPE_NONE"
"DEL_TYPE_DONE"
"DEL_TYPE_WAIT"

I made my pattern like this,
std::string pat("(?<=^[ \\t]?)[A-Z0-9_]+(?=,$)");

but I'm keep getting error message when compiler is tyring to read my pattern.
I don't understand but there is problem with ? mark after \\t
If I get rid of ? mark then it compiles and find only "DEL_TYPE_WAIT"
why can't I use Repeats in the Lookahead? plz help me I'm totaly lost here ;(

thank you

From stackoverflow
  • Just based on POSIX I'd say your regex is "DEL_TYPE_([ND]ONE|WAIT),"

    That's just based on what you've listed above. I would say that the actual issue is with you double escaping the t; you should probably do [ \t\s]* since there may not be just zero or one tab/space.

    Jace Jung : the code I show above is just an example. real one is more complex thought. thank you anyway ^^
  • I found the answer. No from this manual

    Lookbehind

    (?<=pattern) consumes zero characters, only if pattern could be matched against the characters preceding the current position (pattern must be of fixed length).

0 comments:

Post a Comment