Emacs: Wildcards vs Regular Expression
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.
[x-y]
-
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. [chars]
-
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:
- Repetition of a character, a specific number of times.
- Repetition of a pattern.
- Pattern alternatives. (a βorβ condition of several patterns).
- A Pattern with condition on its boundary, such as at beginning of line, end of line, or separated by punctuation.
- Capture a pattern, to be used for replacement.
Emacs Regular Expression
- Regular Expression
- Regex Syntax
- About Quoting Regex
- Case Sensitivity
- How to Insert a Tab or Newline
- Wildcards vs Regex
- Emacs Regex vs Python, JavaScript, Java