Section 4. The WILDMAT Format

The WILDMAT format described here is based on the version first
   developed by Rich Salz [SALZ1992], which was in turn derived from the
   format used in the UNIX "find" command to articulate file names.  It
   was developed to provide a uniform mechanism for matching patterns in
   the same manner that the UNIX shell matches filenames.
4.1.  Wildmat Syntax
   A wildmat is described by the following ABNF [RFC4234] syntax, which
   is an extract of that in Section 9.8.
     wildmat = wildmat-pattern *("," ["!"] wildmat-pattern)
     wildmat-pattern = 1*wildmat-item
     wildmat-item = wildmat-exact / wildmat-wild
     wildmat-exact = %x22-29 / %x2B / %x2D-3E / %x40-5A / %x5E-7E /
          UTF8-non-ascii ; exclude ! * , ? [ \ ]
     wildmat-wild = "*" / "?"
   Note: the characters ",", "\", "[", and "]" are not allowed in
   wildmats, while * and ? are always wildcards.  This should not be a
   problem, since these characters cannot occur in newsgroup names,
   which is the only current use of wildmats.  Backslash is commonly
   used to suppress the special meaning of characters, whereas brackets
   are used to introduce sets.  However, these usages are not universal,
   and interpretation of these characters in the context of UTF-8
   strings is potentially complex and differs from existing practice, so
   they were omitted from this specification.  A future extension to
   this specification may provide semantics for these characters.
4.2.  Wildmat Semantics
   A wildmat is tested against a string and either matches or does not
   match.  To do this, each constituent <wildmat-pattern> is matched
   against the string, and the rightmost pattern that matches is
   identified.  If that <wildmat-pattern> is not preceded with "!", the
   whole wildmat matches.  If it is preceded by "!", or if no <wildmat-
   pattern> matches, the whole wildmat does not match.
   For example, consider the wildmat "a*,!*b,*c*":
   o  The string "aaa" matches because the rightmost match is with "a*".
   o  The string "abb" does not match because the rightmost match is
      with "*b".
   o  The string "ccb" matches because the rightmost match is with
      "*c*".
   o  The string "xxx" does not match because no <wildmat-pattern>
      matches.
   A <wildmat-pattern> matches a string if the string can be broken into
   components, each of which matches the corresponding <wildmat-item> in
   the pattern.  The matches must be in the same order, and the whole
   string must be used in the match.  The pattern is "anchored"; that
   is, the first and last characters in the string must match the first
   and last item, respectively (unless that item is an asterisk matching
   zero characters).
   A <wildmat-exact> matches the same character (which may be more than
   one octet in UTF-8).
   "?" matches exactly one character (which may be more than one octet).
   "*" matches zero or more characters.  It can match an empty string,
   but it cannot match a subsequence of a UTF-8 sequence that is not
   aligned to the character boundaries.
4.3.  Extensions
   An NNTP server or extension MAY extend the syntax or semantics of
   wildmats provided that all wildmats that meet the requirements of
   Section 4.1 have the meaning ascribed to them by Section 4.2.  Future
   editions of this document may also extend wildmats.
4.4.  Examples
   In these examples, $ and @ are used to represent the two octets %xC2
   and %xA3, respectively; $@ is thus the UTF-8 encoding for the pound
   sterling symbol, shown as # in the descriptions.
     Wildmat    Description of strings that match
       abc      The one string "abc"
       abc,def  The two strings "abc" and "def"
       $@       The one character string "#"
       a*       Any string that begins with "a"
       a*b      Any string that begins with "a" and ends with "b"
       a*,*b    Any string that begins with "a" or ends with "b"
       a*,!*b   Any string that begins with "a" and does not end with
                "b"
     a*,!*b,c*  Any string that begins with "a" and does not end with
                "b", and any string that begins with "c" no matter
                what it ends with
     a*,c*,!*b  Any string that begins with "a" or "c" and does not
                end with "b"
       ?a*      Any string with "a" as its second character
       ??a*     Any string with "a" as its third character
       *a?      Any string with "a" as its penultimate character
       *a??     Any string with "a" as its antepenultimate character