All good things are three (how to skip unwanted sub-matches?)
===

<h3>How to consume/skip unwanted matches?</h3>
<!-- language: lang-perl -->

Lets assume we have the following text:

    my $t ='good good *bad !bad -bad "alwaysbad alwaysbad alwaysbad" good';

and I'd like to have a singe regular expression that matches only `good` words. The real content of the symbolic words `good`, `bad`, and `alwaysbad` is, of course, `[0-9A-Za-z_@]+` (`\w+` is fine for this question). To find a `bad`-word, something like `(\s|^)\b\w` at the start of the word would suffice. Stuff in double quotes is always a bad word, even if not prefixed.

This is what I have:

    my $r = qr/
               (?: " [^"]+ " )    # skip quoted part altogether, don't capture
                |                 # OR
               (?<!\S) \b (\w+)   # find words without 'bad' prefix and capture
              /x;

this expression would not capture the quoted part, but still match. Therefore, we'll have a `undefined` empty entry in the match list:

    my @matches = $t =~ /$r/g;
 
    print join "\n", @matches;

      good
      good
             <== (uninitialized value, this comes from the quoted part)
      good

Now the question:

Does anybody know a technique applicable to contemporary perl regular expressions **how to consume a given part of a string but not match is** with a single regex invocation?

The result should, therefore, be:

      good
      good
      good
