|
Boost : |
Subject: Re: [boost] [regex] Support for Perl's (*SKIP)
From: John Maddock (jz.maddock_at_[hidden])
Date: 2015-04-19 06:55:35
> Without (*SKIP), it can be done only by calling regex::search multiple
> times, using an expression like this:
>
> (?-s)//.*+|/\*[\S\s]*?\*/|"(?:\\.|[^"\n])*+"|(\bfoo\b)
>
> and ignoring every match where group 1 wasn't matched. That's presumed
> to be slower, and certainly more inconvenient for the programmer.
I've added a bug report for this:
https://svn.boost.org/trac/boost/ticket/11205
However, in the mean time, there is a much simpler workaround, if you use:
(?x-s) (?# free spacing, dot doesn't match newline)
(?://.*+ (?# eat single-line comment text)
|/\*[\S\s]*?\*/ (?# eat multi-line comment text)
|"(?:\\.|[^"\n])*+" (?# eat string text)
) (?# skip these)
|\b(foo)\b (?# match this)
And if $1 matched, then you have what you were looking for, otherwise
discard. It's not as "neat" as the original, but is no less/more efficient.
HTH, John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk