Boost C++ Libraries: Ticket #11205: Add support for perl (*VERB) directives https://svn.boost.org/trac10/ticket/11205 <p> I'd like to see support for Perl's (*SKIP) regex verb in Boost. </p> <p> There are a number of verbs, but that one has an interesting and frequent use case: it enables searching for an expression but only outside of some contexts. </p> <p> There is a page called "The best regex trick" with details about the process and a number of examples. I can't link to it as this is my first message (I attempted before but it was rejected). It explains how to do it with and without (*SKIP). I've seen several questions in Stack Overflow asking how to accomplish that task, so it seems it's quite frequent to run into that need. </p> <p> Let's say for example that we want to find the string 'foo' as an identifier in C. This is a crude example of a Perl regex that does it (a real one might need to be more elaborate; in particular, backslashes for line continuation are not considered): </p> <blockquote> <p> (?x-s) (?# free spacing, dot doesn't match newline) (?:<em>.*+ (?# eat single-line comment text) </em></p> <blockquote> <p> |/\*[\S\s]*?\*/ (?# eat multi-line comment text) |"(?:<br />.|[<sup>"\n])*+" (?# eat string text) </sup></p> </blockquote> <p> )(*SKIP)(?!) (?# skip these) |\bfoo\b (?# match this) </p> </blockquote> <p> regex::search will match that expression only when foo is present outside of a string or comment. </p> <p> Without (*SKIP), it can be done only by calling regex::search multiple times, using an expression like this: </p> <blockquote> <p> (?-s)<em>.*+|/\*[\S\s]*?\*/|"(?:<br />.|[<sup>"\n])*+"|(\bfoo\b) </sup></em></p> </blockquote> <p> and ignoring every match where group 1 wasn't matched. That's presumed to be slower, and certainly more inconvenient for the programmer. </p> <p> Support for this particular use case would be a great feature to have in the regex engine. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11205 Trac 1.4.3 John Maddock Tue, 06 Oct 2015 16:44:31 GMT status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/11205#comment:1 https://svn.boost.org/trac10/ticket/11205#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> <p> This is now fixed in develop. </p> Ticket