I think you're taking the wrong set of instructions as definitive. Maybe you should play more D&D - where every rule seems to have an exception somewhere else :)

) # .. end of first group (is this missing # a '?' to show it's optional?)
Nope. The first group exists, even if it's empty. That is called out explicitly. The only reason for the ? after the non-capturing group is because the X itself is optional - and not present when the second group is not present.

As for your other post, again, you're using the more precise instructions as definitive instead of the less precise instructions (with explicit examples). If we take the examples as definitive, and fill in their ambiguity with the precise instructions instead of the other way around, we see that the X is always followed by something. That the precise instructions would seem to allow X without anything after them becomes moot because we are starting with the higher-level instructions which already said that wasn't allowed (through the example).

The problem is that communication is a two-way street, and you're using your definitions of "set" and "might" and "zero or one" instead of theirs. That theirs is nonsensical is completely beside the point - they showed us their flawed dictionary through the examples. Not everyone understands that "set" can include the null or empty set. Or that their use of "might" is ambiguous (they mean "might include a, might include b, might include c" and left off the "but must include something" bit, thinking that "set" means "something" and can never be empty).

Think about this as a list of items in perl:

@r = (@$a, @b, c,); # c would be a function call!
In perl, those commas, which represent "X" in the OP's question, are required. Except for the last one. However, in other languages, such as C, that last one is an error. And that follows the requirement - you can have that X, but only if something follows it, though what that is can be anything. To complete the simile, "a" becomes "@", "b" becomes "$", and c becomes "a name (such as a, b, c here)". The OP just can't allow that trailing comma, because he's reading something more like C than Perl. (Of course, in perl, "c", being "a name", isn't actually optional unless the first two are also missing.)

The hardest part about any spec, as always, is figuring out what the author meant as opposed to what they said. And that means understanding who the author is and where they're coming from. In this case, it was a wild-assed guess. But that's one of the beauties of the site - I'm not regularly the one to predict what a petitioner is asking, but it's pretty often that someone does predict it. It just happened to be me this time. :)


In reply to Re^4: perl look ahead regular expression that is optional? by Tanktalus
in thread perl look ahead regular expression that is optional? by bigsipper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.