Next Previous Up Top Contents Index

search-files

3.19.2 Regular expression searching

A regular expression (regexp) allows the specification of the search string to include wild characters, repeated characters, ranges of characters, and alternatives. Strings which follow a specific pattern can be located, which makes regular expression searches very powerful.

The regular expression syntax used is similar to that of Emacs. In addition to ordinary characters, a regular expression can contain the following special characters to produce the search pattern:

.

Matches any single character except a newline. For example,c.r matches any three character string starting withc and ending withr.

*

Matches the previous regexp any number of times (including 0 times). For example,ca*r matches strings beginning withc and ending withr, with any number ofa's in-between.

+

Matches the previous regexp any number of times, but at least once. For example,ca+r matches strings beginning withc and ending withr, with at least onea in-between.

?

Matches the previous regexp either 0 or 1 times. For example,ca?r matches either the stringcr orcar, and nothing else.

^

Matches the next regexp as long as it is at the beginning of a line. For example,^foo matches the stringfoo as long as it is at the beginning of a line.

$

Matches the previous regexp as long as it is at the end of a line. For example,foo$ matches the stringfoo as long as it is at the end of a line.

[ ]

Contains a character set to be used for matching, where the other special characters mentioned do not apply. The empty string is automatically part of the character set. For example,[a.b] matches eithera or. orb or the empty string. The regexpc[ad]*r matches strings beginning withc and ending withr, with any number ofa's andd's in-between.

The characters- and^ have special meanings inside character sets.- defines a range and^ defines a complement character set. For example,[a-d] matches any character in the rangea tod inclusive.[^ab] matches any character excepta orb.

\

Quotes the special characters. For example,\* matches the character* (that is,* has lost its special meaning).

\|

Specifies an alternative. For example,ab\|cd matches eitherab orcd.

\(, \)

Provides a grouping construct. For example,ab\(cd\|ef\) matches eitherabcd orabef.

Regexp Forward Search

Editor Command

Arguments: string
Key sequence: +Ctrl+Sstring
editor:regexp-forward-search-command p &optional string the-point limit

Performs a forward search for string using regular expressions. The search pattern must be terminated with a carriage return before any searching is done. If an empty string is provided, the last regexp search is repeated.
The argument the-point specifies the position from which the search is to start. The default is the current point. limit specifies a limiting point in the buffer for the search. The default is the end of the buffer.
Regexp Reverse Search

Editor Command

Arguments: string
Key sequence: +Ctrl+Rstring
editor:regexp-reverse-search-command p &optional string the-point limit

Performs a backward search for string using regular expressions. The search pattern must be terminated with a carriage return before any searching is done. If an empty string is provided, the last regexp search is repeated.
The argument the-point specifies the position from which the search is to start. The default is one position before the current point. limit specifies a limiting point in the buffer for the search. The default is the current point.

LispWorks Editor User Guide - 15 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker