Emacs: Regex Tutorial
Regular Expression (or regex in short) is a character sequence that represent a pattern for matching text. For example, you can use it to find all email addresses in a file by matching the email address pattern. Regex is used by many functions to check if a string contains certain pattern, or extract it, or replace it with other string.
What is Wrong with Wildcards * ?
The most commonly used commands that use regex are:
list-matching-lines[see Emacs: List/Delete Matching Lines, Sort Lines]
query-replace-regexp[see Emacs: Find Replace in Current File]
- Open a file with many lines.
It will list all lines that contains the regex pattern
th.t, which includes “this”, “that”.
. character in regex is a wildcard, matching any character.
Emacs Regular Expression Syntax
Interactive Emacs Regex Mode
Emacs has a interactive regex mode. It show matches as you type. To go into the mode, Alt+x
regexp-builder. (I don't like this)
I recommend using
to test your pattern.