bash: Pattern Matching

1 
1 3.5.8.1 Pattern Matching
1 ........................
1 
1 Any character that appears in a pattern, other than the special pattern
1 characters described below, matches itself.  The NUL character may not
1 occur in a pattern.  A backslash escapes the following character; the
1 escaping backslash is discarded when matching.  The special pattern
1 characters must be quoted if they are to be matched literally.
1 
1    The special pattern characters have the following meanings:
1 '*'
1      Matches any string, including the null string.  When the 'globstar'
1      shell option is enabled, and '*' is used in a filename expansion
1      context, two adjacent '*'s used as a single pattern will match all
1      files and zero or more directories and subdirectories.  If followed
1      by a '/', two adjacent '*'s will match only directories and
1      subdirectories.
1 '?'
1      Matches any single character.
1 '[...]'
1      Matches any one of the enclosed characters.  A pair of characters
1      separated by a hyphen denotes a RANGE EXPRESSION; any character
1      that falls between those two characters, inclusive, using the
1      current locale's collating sequence and character set, is matched.
1      If the first character following the '[' is a '!' or a '^' then any
1      character not enclosed is matched.  A '-' may be matched by
1      including it as the first or last character in the set.  A ']' may
1      be matched by including it as the first character in the set.  The
1      sorting order of characters in range expressions is determined by
1      the current locale and the values of the 'LC_COLLATE' and 'LC_ALL'
1      shell variables, if set.
1 
1      For example, in the default C locale, '[a-dx-z]' is equivalent to
1      '[abcdxyz]'.  Many locales sort characters in dictionary order, and
1      in these locales '[a-dx-z]' is typically not equivalent to
1      '[abcdxyz]'; it might be equivalent to '[aBbCcDdxXyYz]', for
1      example.  To obtain the traditional interpretation of ranges in
1      bracket expressions, you can force the use of the C locale by
1      setting the 'LC_COLLATE' or 'LC_ALL' environment variable to the
1      value 'C', or enable the 'globasciiranges' shell option.
1 
1      Within '[' and ']', CHARACTER CLASSES can be specified using the
1      syntax '[:'CLASS':]', where CLASS is one of the following classes
1      defined in the POSIX standard:
1           alnum   alpha   ascii   blank   cntrl   digit   graph   lower
1           print   punct   space   upper   word    xdigit
1      A character class matches any character belonging to that class.
1      The 'word' character class matches letters, digits, and the
1      character '_'.
1 
1      Within '[' and ']', an EQUIVALENCE CLASS can be specified using the
1      syntax '[='C'=]', which matches all characters with the same
1      collation weight (as defined by the current locale) as the
1      character C.
1 
1      Within '[' and ']', the syntax '[.'SYMBOL'.]' matches the collating
1      symbol SYMBOL.
1 
1    If the 'extglob' shell option is enabled using the 'shopt' builtin,
1 several extended pattern matching operators are recognized.  In the
1 following description, a PATTERN-LIST is a list of one or more patterns
1 separated by a '|'.  Composite patterns may be formed using one or more
1 of the following sub-patterns:
1 
1 '?(PATTERN-LIST)'
1      Matches zero or one occurrence of the given patterns.
1 
1 '*(PATTERN-LIST)'
1      Matches zero or more occurrences of the given patterns.
1 
1 '+(PATTERN-LIST)'
1      Matches one or more occurrences of the given patterns.
1 
1 '@(PATTERN-LIST)'
1      Matches one of the given patterns.
1 
1 '!(PATTERN-LIST)'
1      Matches anything except one of the given patterns.
1