Go to the next section.

@paragraphindent 2

@defcodeindex cn

Copyright (C) 1992 Free Software Foundation.

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the section entitled "GNU General Public License" is included exactly as in the original, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that the section entitled "GNU General Public License" may be included in a translation approved by the Free Software Foundation instead of in the original English.

Overview

A regular expression (or regexp, or pattern) is a text string that describes some (mathematical) set of strings. A regexp r matches a string s if s is in the set of strings described by r.

Using the Regex library, you can:

Some regular expressions match only one string, i.e., the set they describe has only one member. For example, the regular expression `foo' matches the string `foo' and no others. Other regular expressions match more than one string, i.e., the set they describe has more than one member. For example, the regular expression `f*' matches the set of strings made up of any number (including zero) of `f's. As you can see, some characters in regular expressions match themselves (such as `f') and some don't (such as `*'); the ones that don't match themselves instead let you specify patterns that describe many different strings.

To either match or search for a regular expression with the Regex library functions, you must first compile it with a Regex pattern compiling function. A compiled pattern is a regular expression converted to the internal format used by the library functions. Once you've compiled a pattern, you can use it for matching or searching any number of times.

The Regex library consists of two source files: `regex.h' and `regex.c'. Regex provides three groups of functions with which you can operate on regular expressions. One group--the GNU group--is more powerful but not completely compatible with the other two, namely the POSIX and Berkeley UNIX groups; its interface was designed specifically for GNU. The other groups have the same interfaces as do the regular expression functions in POSIX and Berkeley UNIX.

We wrote this chapter with programmers in mind, not users of programs--such as Emacs--that use Regex. We describe the Regex library in its entirety, not how to write regular expressions that a particular program understands.

Go to the next section.