Filename globbing patterns and regular expressions have a syntax overlap, to some degree, but they work in fundamentally different ways.
The regular expression e
will match (in) the string hello
while the filename globbing pattern e
would not. Globbing patterns are implicitly anchored, so the glob pattern e
would be equivalent to a regular expression looking something like ^e$
, but their application may be different (the regular expression would match against a complete line in a text, whereas the glob pattern would typically match against a single filename).
Filename globbing patterns also don't have any special characters that qualifies the previous expression, such as *
or ?
in a regular expression, or any facility to group parts of expressions as (...)
does in a regular expression, or to alternate between possible sub-patterns as |
does in a regular expression. Some shells obviously add some of this, as bash
does with shopt -s extglob
enabled, for example.
Globbing patterns have different use from regular expressions. Regular expressions are primarily used for selecting/matching strings from texts, whereas filename globbing patterns are primarily (but not exclusively) used for matching filenames or generating lists of existing names from a directory. Globbing patterns are used to match strings in e.g. case ... esac
, but a POSIX shell never uses regular expressions for generating lists of names from a directory, unless extended with that capability.
Both types of patterns are defined by the POSIX standard:
Of globbing patterns, the standard starts out by saying
The pattern matching notation described in this section is used to specify patterns for matching strings in the shell. Historically, pattern matching notation is related to, but slightly different from, the regular expression notation described in XBD Regular Expressions. For this reason, the description of the rules for this pattern matching notation are based on the description of regular expression notation, modified to account for the differences.
There are several "dialects" of regular expressions, such as PCRE which you mention, but filename globbing patterns can not really be said to be one of them.
There are several pattern languages that are similar to the shell's filename globbing patterns, such as the patterns used in SQL queries with LIKE
. These are all quite simple and generally provided as a convenient way of matching bits of strings. Regular expressions are, in comparison, a whole lot more complex.
You mention "bash
regular expressions". The bash
shell does support regular expressions, but not for filename matching. Within [[ ... ]]
, the =~
operator performs a regular expression match of the string on the left hand side against the regular expression on the right. The type of regular expressions that the bash
shell supports in this way are the standard extended set of regular expressions. See the bash
manual on your system for further information about this.