Emacs: Wildcards vs Regular Expression

By Xah Lee. Date: . Last updated: .

What is String Wildcards (Glob Pattern)

In shell, you can use wildcards to match filename, e.g. ls *.jpg to list all jpg files. This system is called string wildcards or known as glob pattern in unix. Wildcards is simple and easy to understand.

String Wildcard Syntax

There is no standard syntax. Here's a basic list of String Wildcard Syntax features supported by most tools.

Match 0 or more of any character. Example, *.jpg match all file names ending in .jpg.
Match any character.
Match a range of characters x to y.
Typically used as [a-z] and or [0-9]. the range is defined by the char's id.
Match any characters in chars.
e.g. [abc].

Regular Expression for Matching More Complex Patterns

Regular Expression is much more powerful than wildcards.

Here's example of patterns that regex can represent, but wildcards cannot:

Emacs, commands using regex