Jade uses the regexp(3) package by Henry Spencer, with some modifications that I have added. It comes with this heading:
Copyright (c) 1986 by University of Toronto.
Written by Henry Spencer. Not derived from licensed software.Permission is granted to anyone to use this software for any purpose on any computer system, and to redistribute it freely, subject to the following restrictions:
- The author is not responsible for the consequences of use of this software, no matter how awful, even if they arise from defects in it.
- The origin of this software must not be misrepresented, either by explicit claim or by omission.
- Altered versions must be plainly marked as such, and must not be misrepresented as being the original software.
The syntax of a regular expression (or regexp) is as follows (this is quoted from the regexp(3) manual page):
A regular expression is zero or more branches, separated by `|'. It matches anything that matches one of the branches.
A branch is zero or more pieces, concatenated. It matches a match for the first, followed by a match for the second, etc.
A piece is an atom possibly followed by `*', `+', or `?'. An atom followed by `*' matches a sequence of 0 or more matches of the atom. An atom followed by `+' matches a sequence of 1 or more matches of the atom. An atom followed by `?' matches a match of the atom, or the null string.
An atom is a regular expression in parentheses (matching a match for the regular expression), a range (see below), `.' (matching any single character), `^' (matching the null string at the beginning of the input string), `$' (matching the null string at the end of the input string), a `\' followed by a single character (matching that character), or a single character with no other significance (matching that character).
A range is a sequence of characters enclosed in `[]'. It normally matches any single character from the sequence. If the sequence begins with `^', it matches any single character not from the rest of the sequence. If two characters in the sequence are separated by `-', this is shorthand for the full list of ASCII characters between them (e.g. `[0-9]' matches any decimal digit). To include a literal `]' in the sequence, make it the first character (following a possible `^'). To include a literal `-', make it the first or last character.
Some example legal regular expressions could be:
As well as being matched against, regexps also provide a means of "remembering" portions of the string that they match. The first nine parenthesised expressions that are matched and the whole match are recorded so that they can be used later.
The main use for this is in the command to replace a previously found regexp
with the Lisp functions regexp-expand, regexp-expand-line and
replace-regexp. The string which is given as the template (i.e. the
string that replaces the matched string) is expanded inserting these recorded
strings where asked to.
Each occurrence of `\C' in the template is a candidate for expansion. C can be one of:
For example, if a regexp of `:([0-9]+):' matches a line `foo:123:bar', the expansion template `x_\1' would produce `x_123'.
Go to the first, previous, next, last section, table of contents.