Post

17 Regular Expressions for Search and Replacement Operation

Characters for creating regular expressions:

Character(s)Match
^Matches the beginning of a line.
$Matches the end of a line.
.Matches any single character (like ? in filenames).
.*Matches any group of zero or more characters (. matches any character and* matches zero or more of the previous character).
\<Matches the beginning of a word.
\>Matches the end of a word.
[ ]Matches any character specified within the brackets; for example, [a-z] matches any alphabetic character.
\s, \SMatches any whitespace character: space, a newline, a tab, a carriage return, a formfeed, or a backspace;\S matches any character except whitespace.
\d, \DMatches any single digit, 0-9;\D matches any character but a digit.
\w, \WMatches any “word” character (upper- and lowercase letters, digits, and the underscore character);\W matches any character but these.

Mastering Regular Expressions by Jeffrey Friedl (O’Reilly)

Regular expression search commandsegular expression search commands:

KeystrokesCommand nameAction
C-M-s Enter Edit Search Regexp Forwardre-search-forwardSearch for a regular expression forward.
C-M-r Enter Edit Search Regexp Backwardsre-search-backwardSearch for a regular expression backward.
C-M-s Edit Search Incremental Search Forward Regexpisearch-forward-regexpSearch incrementally forward for a regular expression.
C-M-r Edit Search Incremental Search Backward Regexpisearch-backward-regexpSearch incrementally backward for a regular expression.
C-M-% Edit Replace Replace Regexpquery-replace-regexpQuery-replace a regular expression.
(none)replace-regexpGlobally replace a regular expression unconditionally (use with caution).
This post is licensed under CC BY 4.0 by the author.