Next: Regexps, Previous: Word Search, Up: Search [Contents][Index]
A regular expression (regexp, for short) is a pattern that denotes a (possibly infinite) set of strings. Searching for matches for a regexp is a powerful operation that editors on Unix systems have traditionally offered.
To gain a thorough understanding of regular expressions and how to use them to best advantage, we recommend that you study Mastering Regular Expressions, by Jeffrey E.F. Friedl, O’Reilly and Associates, 1997. (It’s known as the "Hip Owls" book, because of the picture on its cover.) You might also read the manuals to (gawk)Top, (ed)Top, sed, grep, (perl)Top, (regex)Top, (rx)Top, pcre, and (flex)Top, which also make good use of regular expressions.
The SXEmacs regular expression syntax most closely resembles that of ed, or grep, the GNU versions of which all utilize the GNU regex library. SXEmacs’ version of regex has recently been extended with some Perl–like capabilities, described in the next section.
In SXEmacs, you can search for the next match for a regexp either incrementally or not.
Incremental search for a regexp is done by typing M-C-s
(isearch-forward-regexp
). This command reads a search string
incrementally just like C-s, but it treats the search string as a
regexp rather than looking for an exact match against the text in the
buffer. Each time you add text to the search string, you make the regexp
longer, and the new regexp is searched for. A reverse regexp search command
isearch-backward-regexp
also exists, bound to M-C-r.
All of the control characters that do special things within an ordinary incremental search have the same functionality in incremental regexp search. Typing C-s or C-r immediately after starting a search retrieves the last incremental search regexp used: incremental regexp and non-regexp searches have independent defaults.
Non-incremental search for a regexp is done by the functions
re-search-forward
and re-search-backward
. You can invoke
them with M-x or bind them to keys. You can also call
re-search-forward
by way of incremental regexp search with
M-C-s RET; similarly for re-search-backward
with
M-C-r RET.
Next: Regexps, Previous: Word Search, Up: Search [Contents][Index]