*** empty log message ***
[bpt/emacs.git] / lispref / searching.texi
CommitLineData
7015aca4
RS
1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual.
651f374c 3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2002, 2003,
ceb4c4d3 4@c 2004, 2005, 2006 Free Software Foundation, Inc.
7015aca4
RS
5@c See the file elisp.texi for copying conditions.
6@setfilename ../info/searching
f9f59935 7@node Searching and Matching, Syntax Tables, Non-ASCII Characters, Top
7015aca4
RS
8@chapter Searching and Matching
9@cindex searching
10
11 GNU Emacs provides two ways to search through a buffer for specified
12text: exact string searches and regular expression searches. After a
13regular expression search, you can examine the @dfn{match data} to
14determine which text matched the whole regular expression or various
15portions of it.
16
17@menu
18* String Search:: Search for an exact match.
99543e8b 19* Searching and Case:: Case-independent or case-significant searching.
7015aca4
RS
20* Regular Expressions:: Describing classes of strings.
21* Regexp Search:: Searching for a match for a regexp.
22697dac 22* POSIX Regexps:: Searching POSIX-style for the longest match.
2a233172
RS
23* Match Data:: Finding out which part of the text matched,
24 after a string or regexp search.
99543e8b 25* Search and Replace:: Commands that loop, searching and replacing.
7015aca4
RS
26* Standard Regexps:: Useful regexps for finding sentences, pages,...
27@end menu
28
29 The @samp{skip-chars@dots{}} functions also perform a kind of searching.
30@xref{Skipping Characters}.
31
32@node String Search
33@section Searching for Strings
34@cindex string search
35
36 These are the primitive functions for searching through the text in a
37buffer. They are meant for use in programs, but you may call them
8241495d
RS
38interactively. If you do so, they prompt for the search string; the
39arguments @var{limit} and @var{noerror} are @code{nil}, and @var{repeat}
40is 1.
7015aca4 41
f9f59935
RS
42 These search functions convert the search string to multibyte if the
43buffer is multibyte; they convert the search string to unibyte if the
44buffer is unibyte. @xref{Text Representations}.
45
7015aca4 46@deffn Command search-forward string &optional limit noerror repeat
f9f59935 47This function searches forward from point for an exact match for
7015aca4
RS
48@var{string}. If successful, it sets point to the end of the occurrence
49found, and returns the new value of point. If no match is found, the
50value and side effects depend on @var{noerror} (see below).
51@c Emacs 19 feature
52
f9f59935 53In the following example, point is initially at the beginning of the
7015aca4
RS
54line. Then @code{(search-forward "fox")} moves point after the last
55letter of @samp{fox}:
56
57@example
58@group
59---------- Buffer: foo ----------
60@point{}The quick brown fox jumped over the lazy dog.
61---------- Buffer: foo ----------
62@end group
63
64@group
65(search-forward "fox")
66 @result{} 20
67
68---------- Buffer: foo ----------
69The quick brown fox@point{} jumped over the lazy dog.
70---------- Buffer: foo ----------
71@end group
72@end example
73
f9f59935 74The argument @var{limit} specifies the upper bound to the search. (It
7015aca4
RS
75must be a position in the current buffer.) No match extending after
76that position is accepted. If @var{limit} is omitted or @code{nil}, it
77defaults to the end of the accessible portion of the buffer.
78
79@kindex search-failed
f9f59935 80What happens when the search fails depends on the value of
7015aca4
RS
81@var{noerror}. If @var{noerror} is @code{nil}, a @code{search-failed}
82error is signaled. If @var{noerror} is @code{t}, @code{search-forward}
83returns @code{nil} and does nothing. If @var{noerror} is neither
84@code{nil} nor @code{t}, then @code{search-forward} moves point to the
f9f59935
RS
85upper bound and returns @code{nil}. (It would be more consistent now to
86return the new position of point in that case, but some existing
87programs may depend on a value of @code{nil}.)
7015aca4 88
50363cd8
RS
89The argument @var{noerror} only affects valid searches which fail to
90find a match. Invalid arguments cause errors regardless of
91@var{noerror}.
92
61cfa852
RS
93If @var{repeat} is supplied (it must be a positive number), then the
94search is repeated that many times (each time starting at the end of the
95previous time's match). If these successive searches succeed, the
96function succeeds, moving point and returning its new value. Otherwise
bcb6b6b8
LT
97the search fails, with results depending on the value of
98@var{noerror}, as described above.
7015aca4
RS
99@end deffn
100
101@deffn Command search-backward string &optional limit noerror repeat
102This function searches backward from point for @var{string}. It is
103just like @code{search-forward} except that it searches backwards and
104leaves point at the beginning of the match.
105@end deffn
106
107@deffn Command word-search-forward string &optional limit noerror repeat
108@cindex word search
109This function searches forward from point for a ``word'' match for
110@var{string}. If it finds a match, it sets point to the end of the
111match found, and returns the new value of point.
112@c Emacs 19 feature
113
114Word matching regards @var{string} as a sequence of words, disregarding
115punctuation that separates them. It searches the buffer for the same
116sequence of words. Each word must be distinct in the buffer (searching
117for the word @samp{ball} does not match the word @samp{balls}), but the
118details of punctuation and spacing are ignored (searching for @samp{ball
119boy} does match @samp{ball. Boy!}).
120
121In this example, point is initially at the beginning of the buffer; the
122search leaves it between the @samp{y} and the @samp{!}.
123
124@example
125@group
126---------- Buffer: foo ----------
127@point{}He said "Please! Find
128the ball boy!"
129---------- Buffer: foo ----------
130@end group
131
132@group
133(word-search-forward "Please find the ball, boy.")
134 @result{} 35
135
136---------- Buffer: foo ----------
137He said "Please! Find
138the ball boy@point{}!"
139---------- Buffer: foo ----------
140@end group
141@end example
142
5bb8ca2a
RS
143If @var{limit} is non-@code{nil}, it must be a position in the current
144buffer; it specifies the upper bound to the search. The match found
145must not extend after that position.
7015aca4
RS
146
147If @var{noerror} is @code{nil}, then @code{word-search-forward} signals
148an error if the search fails. If @var{noerror} is @code{t}, then it
149returns @code{nil} instead of signaling an error. If @var{noerror} is
150neither @code{nil} nor @code{t}, it moves point to @var{limit} (or the
bcb6b6b8 151end of the accessible portion of the buffer) and returns @code{nil}.
7015aca4
RS
152
153If @var{repeat} is non-@code{nil}, then the search is repeated that many
154times. Point is positioned at the end of the last match.
155@end deffn
156
157@deffn Command word-search-backward string &optional limit noerror repeat
158This function searches backward from point for a word match to
159@var{string}. This function is just like @code{word-search-forward}
160except that it searches backward and normally leaves point at the
161beginning of the match.
162@end deffn
163
99543e8b
RS
164@node Searching and Case
165@section Searching and Case
166@cindex searching and case
167
168 By default, searches in Emacs ignore the case of the text they are
169searching through; if you specify searching for @samp{FOO}, then
170@samp{Foo} or @samp{foo} is also considered a match. This applies to
171regular expressions, too; thus, @samp{[aB]} would match @samp{a} or
172@samp{A} or @samp{b} or @samp{B}.
173
174 If you do not want this feature, set the variable
175@code{case-fold-search} to @code{nil}. Then all letters must match
176exactly, including case. This is a buffer-local variable; altering the
177variable affects only the current buffer. (@xref{Intro to
178Buffer-Local}.) Alternatively, you may change the value of
179@code{default-case-fold-search}, which is the default value of
180@code{case-fold-search} for buffers that do not override it.
181
182 Note that the user-level incremental search feature handles case
183distinctions differently. When given a lower case letter, it looks for
184a match of either case, but when given an upper case letter, it looks
185for an upper case letter only. But this has nothing to do with the
186searching functions used in Lisp code.
187
188@defopt case-replace
189This variable determines whether the higher level replacement
190functions should preserve case. If the variable is @code{nil}, that
191means to use the replacement text verbatim. A non-@code{nil} value
192means to convert the case of the replacement text according to the
193text being replaced.
194
195This variable is used by passing it as an argument to the function
196@code{replace-match}. @xref{Replacing Match}.
197@end defopt
198
199@defopt case-fold-search
200This buffer-local variable determines whether searches should ignore
201case. If the variable is @code{nil} they do not ignore case; otherwise
202they do ignore case.
203@end defopt
204
205@defvar default-case-fold-search
206The value of this variable is the default value for
207@code{case-fold-search} in buffers that do not override it. This is the
208same as @code{(default-value 'case-fold-search)}.
209@end defvar
210
7015aca4
RS
211@node Regular Expressions
212@section Regular Expressions
213@cindex regular expression
214@cindex regexp
215
216 A @dfn{regular expression} (@dfn{regexp}, for short) is a pattern that
217denotes a (possibly infinite) set of strings. Searching for matches for
218a regexp is a very powerful operation. This section explains how to write
219regexps; the following section says how to search for them.
220
85b6b13c
RS
221@findex re-builder
222@cindex authoring regular expressions
223 For convenient interactive development of regular expressions, you
224can use the @kbd{M-x re-builder} command. It provides a convenient
225interface for creating regular expressions, by giving immediate visual
226feedback in a separate buffer. As you edit the regexp, all its
227matches in the target buffer are highlighted. Each parenthesized
228sub-expression of the regexp is shown in a distinct face, which makes
229it easier to verify even very complex regexps.
230
7015aca4
RS
231@menu
232* Syntax of Regexps:: Rules for writing regular expressions.
233* Regexp Example:: Illustrates regular expression syntax.
bcb6b6b8 234* Regexp Functions:: Functions for operating on regular expressions.
7015aca4
RS
235@end menu
236
237@node Syntax of Regexps
238@subsection Syntax of Regular Expressions
239
61cfa852
RS
240 Regular expressions have a syntax in which a few characters are
241special constructs and the rest are @dfn{ordinary}. An ordinary
179a6f21
LT
242character is a simple regular expression that matches that character
243and nothing else. The special characters are @samp{.}, @samp{*},
244@samp{+}, @samp{?}, @samp{[}, @samp{^}, @samp{$}, and @samp{\}; no new
245special characters will be defined in the future. The character
246@samp{]} is special if it ends a character alternative (see later).
247The character @samp{-} is special inside a character alternative. A
248@samp{[:} and balancing @samp{:]} enclose a character class inside a
249character alternative. Any other character appearing in a regular
250expression is ordinary, unless a @samp{\} precedes it.
7015aca4 251
8241495d 252 For example, @samp{f} is not a special character, so it is ordinary, and
7015aca4
RS
253therefore @samp{f} is a regular expression that matches the string
254@samp{f} and no other string. (It does @emph{not} match the string
8241495d
RS
255@samp{fg}, but it does match a @emph{part} of that string.) Likewise,
256@samp{o} is a regular expression that matches only @samp{o}.@refill
7015aca4 257
8241495d 258 Any two regular expressions @var{a} and @var{b} can be concatenated. The
61cfa852 259result is a regular expression that matches a string if @var{a} matches
7015aca4
RS
260some amount of the beginning of that string and @var{b} matches the rest of
261the string.@refill
262
8241495d 263 As a simple example, we can concatenate the regular expressions @samp{f}
7015aca4
RS
264and @samp{o} to get the regular expression @samp{fo}, which matches only
265the string @samp{fo}. Still trivial. To do something more powerful, you
8241495d
RS
266need to use one of the special regular expression constructs.
267
268@menu
269* Regexp Special:: Special characters in regular expressions.
270* Char Classes:: Character classes used in regular expressions.
271* Regexp Backslash:: Backslash-sequences in regular expressions.
272@end menu
273
274@node Regexp Special
275@subsubsection Special Characters in Regular Expressions
276
277 Here is a list of the characters that are special in a regular
278expression.
7015aca4 279
7dd3d99f 280@need 800
969fe9b5
RS
281@table @asis
282@item @samp{.}@: @r{(Period)}
7015aca4
RS
283@cindex @samp{.} in regexp
284is a special character that matches any single character except a newline.
285Using concatenation, we can make regular expressions like @samp{a.b}, which
286matches any three-character string that begins with @samp{a} and ends with
287@samp{b}.@refill
288
969fe9b5 289@item @samp{*}
7015aca4 290@cindex @samp{*} in regexp
1cd71ce0
RS
291is not a construct by itself; it is a postfix operator that means to
292match the preceding regular expression repetitively as many times as
293possible. Thus, @samp{o*} matches any number of @samp{o}s (including no
294@samp{o}s).
7015aca4
RS
295
296@samp{*} always applies to the @emph{smallest} possible preceding
1cd71ce0
RS
297expression. Thus, @samp{fo*} has a repeating @samp{o}, not a repeating
298@samp{fo}. It matches @samp{f}, @samp{fo}, @samp{foo}, and so on.
7015aca4 299
f9f59935
RS
300The matcher processes a @samp{*} construct by matching, immediately, as
301many repetitions as can be found. Then it continues with the rest of
302the pattern. If that fails, backtracking occurs, discarding some of the
303matches of the @samp{*}-modified construct in the hope that that will
304make it possible to match the rest of the pattern. For example, in
305matching @samp{ca*ar} against the string @samp{caaar}, the @samp{a*}
306first tries to match all three @samp{a}s; but the rest of the pattern is
7015aca4 307@samp{ar} and there is only @samp{r} left to match, so this try fails.
f9f59935 308The next alternative is for @samp{a*} to match only two @samp{a}s. With
bc023640 309this choice, the rest of the regexp matches successfully.
7015aca4 310
bc023640
RS
311@strong{Warning:} Nested repetition operators take a long time,
312or even forever, if they
342fd6cd
RS
313lead to ambiguous matching. For example, trying to match the regular
314expression @samp{\(x+y*\)*a} against the string
315@samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz} could take hours before it
316ultimately fails. Emacs must try each way of grouping the 35
317@samp{x}s before concluding that none of them can work. Even worse,
318@samp{\(x*\)*} can match the null string in infinitely many ways, so
319it causes an infinite loop. To avoid these problems, check nested
bc023640
RS
320repetitions carefully, to make sure that they do not cause combinatorial
321explosions in backtracking.
73031603 322
969fe9b5 323@item @samp{+}
7015aca4 324@cindex @samp{+} in regexp
1cd71ce0
RS
325is a postfix operator, similar to @samp{*} except that it must match
326the preceding expression at least once. So, for example, @samp{ca+r}
7015aca4
RS
327matches the strings @samp{car} and @samp{caaaar} but not the string
328@samp{cr}, whereas @samp{ca*r} matches all three strings.
329
969fe9b5 330@item @samp{?}
7015aca4 331@cindex @samp{?} in regexp
f9f59935 332is a postfix operator, similar to @samp{*} except that it must match the
1cd71ce0
RS
333preceding expression either once or not at all. For example,
334@samp{ca?r} matches @samp{car} or @samp{cr}; nothing else.
7015aca4 335
c082a348
RS
336@item @samp{*?}, @samp{+?}, @samp{??}
337These are ``non-greedy'' variants of the operators @samp{*}, @samp{+}
338and @samp{?}. Where those operators match the largest possible
339substring (consistent with matching the entire containing expression),
340the non-greedy variants match the smallest possible substring
341(consistent with matching the entire containing expression).
342
343For example, the regular expression @samp{c[ad]*a} when applied to the
344string @samp{cdaaada} matches the whole string; but the regular
345expression @samp{c[ad]*?a}, applied to that same string, matches just
346@samp{cda}. (The smallest possible match here for @samp{[ad]*?} that
347permits the whole expression to match is @samp{d}.)
348
969fe9b5
RS
349@item @samp{[ @dots{} ]}
350@cindex character alternative (in regexp)
7015aca4
RS
351@cindex @samp{[} in regexp
352@cindex @samp{]} in regexp
969fe9b5
RS
353is a @dfn{character alternative}, which begins with @samp{[} and is
354terminated by @samp{]}. In the simplest case, the characters between
355the two brackets are what this character alternative can match.
1cd71ce0
RS
356
357Thus, @samp{[ad]} matches either one @samp{a} or one @samp{d}, and
358@samp{[ad]*} matches any string composed of just @samp{a}s and @samp{d}s
359(including the empty string), from which it follows that @samp{c[ad]*r}
360matches @samp{cr}, @samp{car}, @samp{cdr}, @samp{caddaar}, etc.
361
969fe9b5
RS
362You can also include character ranges in a character alternative, by
363writing the starting and ending characters with a @samp{-} between them.
bcb6b6b8
LT
364Thus, @samp{[a-z]} matches any lower-case @acronym{ASCII} letter.
365Ranges may be intermixed freely with individual characters, as in
366@samp{[a-z$%.]}, which matches any lower case @acronym{ASCII} letter
367or @samp{$}, @samp{%} or period.
1cd71ce0
RS
368
369Note that the usual regexp special characters are not special inside a
86494bd5 370character alternative. A completely different set of characters is
969fe9b5 371special inside character alternatives: @samp{]}, @samp{-} and @samp{^}.
1cd71ce0 372
969fe9b5
RS
373To include a @samp{]} in a character alternative, you must make it the
374first character. For example, @samp{[]a]} matches @samp{]} or @samp{a}.
375To include a @samp{-}, write @samp{-} as the first or last character of
376the character alternative, or put it after a range. Thus, @samp{[]-]}
377matches both @samp{]} and @samp{-}.
7015aca4 378
969fe9b5
RS
379To include @samp{^} in a character alternative, put it anywhere but at
380the beginning.
7015aca4 381
8f17d892
RS
382The beginning and end of a range of multibyte characters must be in
383the same character set (@pxref{Character Sets}). Thus,
384@code{"[\x8e0-\x97c]"} is invalid because character 0x8e0 (@samp{a}
385with grave accent) is in the Emacs character set for Latin-1 but the
386character 0x97c (@samp{u} with diaeresis) is in the Emacs character
387set for Latin-2. (We use Lisp string syntax to write that example,
388and a few others in the next few paragraphs, in order to include hex
389escape sequences in them.)
6cc089d2
DL
390
391If a range starts with a unibyte character @var{c} and ends with a
392multibyte character @var{c2}, the range is divided into two parts: one
393is @samp{@var{c}..?\377}, the other is @samp{@var{c1}..@var{c2}}, where
394@var{c1} is the first character of the charset to which @var{c2}
395belongs.
177c0ea7 396
ad800164 397You cannot always match all non-@acronym{ASCII} characters with the regular
8f17d892 398expression @code{"[\200-\377]"}. This works when searching a unibyte
8241495d 399buffer or string (@pxref{Text Representations}), but not in a multibyte
ad800164 400buffer or string, because many non-@acronym{ASCII} characters have codes
8f17d892 401above octal 0377. However, the regular expression @code{"[^\000-\177]"}
ad800164 402does match all non-@acronym{ASCII} characters (see below regarding @samp{^}),
8241495d 403in both multibyte and unibyte representations, because only the
ad800164 404@acronym{ASCII} characters are excluded.
8241495d 405
63f508b4 406A character alternative can also specify named
8241495d
RS
407character classes (@pxref{Char Classes}). This is a POSIX feature whose
408syntax is @samp{[:@var{class}:]}. Using a character class is equivalent
409to mentioning each of the characters in that class; but the latter is
410not feasible in practice, since some classes include thousands of
411different characters.
412
969fe9b5 413@item @samp{[^ @dots{} ]}
7015aca4 414@cindex @samp{^} in regexp
342fd6cd
RS
415@samp{[^} begins a @dfn{complemented character alternative}. This
416matches any character except the ones specified. Thus,
417@samp{[^a-z0-9A-Z]} matches all characters @emph{except} letters and
418digits.
7015aca4 419
969fe9b5 420@samp{^} is not special in a character alternative unless it is the first
7015aca4 421character. The character following the @samp{^} is treated as if it
1cd71ce0 422were first (in other words, @samp{-} and @samp{]} are not special there).
7015aca4 423
969fe9b5 424A complemented character alternative can match a newline, unless newline is
1cd71ce0
RS
425mentioned as one of the characters not to match. This is in contrast to
426the handling of regexps in programs such as @code{grep}.
7015aca4 427
969fe9b5 428@item @samp{^}
7015aca4 429@cindex beginning of line in regexp
bcb6b6b8
LT
430When matching a buffer, @samp{^} matches the empty string, but only at the
431beginning of a line in the text being matched (or the beginning of the
432accessible portion of the buffer). Otherwise it fails to match
433anything. Thus, @samp{^foo} matches a @samp{foo} that occurs at the
434beginning of a line.
7015aca4 435
61cfa852 436When matching a string instead of a buffer, @samp{^} matches at the
8f17d892 437beginning of the string or after a newline character.
7015aca4 438
8241495d
RS
439For historical compatibility reasons, @samp{^} can be used only at the
440beginning of the regular expression, or after @samp{\(} or @samp{\|}.
441
969fe9b5 442@item @samp{$}
7015aca4 443@cindex @samp{$} in regexp
8241495d 444@cindex end of line in regexp
bcb6b6b8
LT
445is similar to @samp{^} but matches only at the end of a line (or the
446end of the accessible portion of the buffer). Thus, @samp{x+$}
447matches a string of one @samp{x} or more at the end of a line.
7015aca4 448
61cfa852 449When matching a string instead of a buffer, @samp{$} matches at the end
8f17d892 450of the string or before a newline character.
7015aca4 451
8241495d
RS
452For historical compatibility reasons, @samp{$} can be used only at the
453end of the regular expression, or before @samp{\)} or @samp{\|}.
454
969fe9b5 455@item @samp{\}
7015aca4
RS
456@cindex @samp{\} in regexp
457has two functions: it quotes the special characters (including
458@samp{\}), and it introduces additional special constructs.
459
460Because @samp{\} quotes special characters, @samp{\$} is a regular
61cfa852
RS
461expression that matches only @samp{$}, and @samp{\[} is a regular
462expression that matches only @samp{[}, and so on.
7015aca4
RS
463
464Note that @samp{\} also has special meaning in the read syntax of Lisp
465strings (@pxref{String Type}), and must be quoted with @samp{\}. For
466example, the regular expression that matches the @samp{\} character is
467@samp{\\}. To write a Lisp string that contains the characters
468@samp{\\}, Lisp syntax requires you to quote each @samp{\} with another
469@samp{\}. Therefore, the read syntax for a regular expression matching
470@samp{\} is @code{"\\\\"}.@refill
471@end table
472
b22f3a19 473@strong{Please note:} For historical compatibility, special characters
7015aca4
RS
474are treated as ordinary ones if they are in contexts where their special
475meanings make no sense. For example, @samp{*foo} treats @samp{*} as
476ordinary since there is no preceding expression on which the @samp{*}
61cfa852
RS
477can act. It is poor practice to depend on this behavior; quote the
478special character anyway, regardless of where it appears.@refill
7015aca4 479
179a6f21
LT
480As a @samp{\} is not special inside a character alternative, it can
481never remove the special meaning of @samp{-} or @samp{]}. So you
482should not quote these characters when they have no special meaning
483either. This would not clarify anything, since backslashes can
484legitimately precede these characters where they @emph{have} special
ba44fca9 485meaning, as in @samp{[^\]} (@code{"[^\\]"} for Lisp string syntax),
179a6f21
LT
486which matches any single character except a backslash.
487
488In practice, most @samp{]} that occur in regular expressions close a
489character alternative and hence are special. However, occasionally a
490regular expression may try to match a complex pattern of literal
491@samp{[} and @samp{]}. In such situations, it sometimes may be
492necessary to carefully parse the regexp from the start to determine
493which square brackets enclose a character alternative. For example,
ba44fca9
LT
494@samp{[^][]]} consists of the complemented character alternative
495@samp{[^][]} (which matches any single character that is not a square
1ab7aea1 496bracket), followed by a literal @samp{]}.
179a6f21
LT
497
498The exact rules are that at the beginning of a regexp, @samp{[} is
499special and @samp{]} not. This lasts until the first unquoted
500@samp{[}, after which we are in a character alternative; @samp{[} is
501no longer special (except when it starts a character class) but @samp{]}
502is special, unless it immediately follows the special @samp{[} or that
503@samp{[} followed by a @samp{^}. This lasts until the next special
504@samp{]} that does not end a character class. This ends the character
505alternative and restores the ordinary syntax of regular expressions;
506an unquoted @samp{[} is special again and a @samp{]} not.
507
8241495d
RS
508@node Char Classes
509@subsubsection Character Classes
510@cindex character classes in regexp
511
512 Here is a table of the classes you can use in a character alternative,
63f508b4 513and what they mean:
8241495d
RS
514
515@table @samp
516@item [:ascii:]
ad800164 517This matches any @acronym{ASCII} (unibyte) character.
8241495d
RS
518@item [:alnum:]
519This matches any letter or digit. (At present, for multibyte
520characters, it matches anything that has word syntax.)
521@item [:alpha:]
522This matches any letter. (At present, for multibyte characters, it
523matches anything that has word syntax.)
524@item [:blank:]
525This matches space and tab only.
526@item [:cntrl:]
ad800164 527This matches any @acronym{ASCII} control character.
8241495d
RS
528@item [:digit:]
529This matches @samp{0} through @samp{9}. Thus, @samp{[-+[:digit:]]}
530matches any digit, as well as @samp{+} and @samp{-}.
531@item [:graph:]
ad800164 532This matches graphic characters---everything except @acronym{ASCII} control
75708135 533characters, space, and the delete character.
8241495d
RS
534@item [:lower:]
535This matches any lower-case letter, as determined by
536the current case table (@pxref{Case Tables}).
537@item [:nonascii:]
ad800164 538This matches any non-@acronym{ASCII} (multibyte) character.
8241495d 539@item [:print:]
ad800164 540This matches printing characters---everything except @acronym{ASCII} control
caccdcbb 541characters and the delete character.
8241495d
RS
542@item [:punct:]
543This matches any punctuation character. (At present, for multibyte
544characters, it matches anything that has non-word syntax.)
545@item [:space:]
546This matches any character that has whitespace syntax
547(@pxref{Syntax Class Table}).
548@item [:upper:]
549This matches any upper-case letter, as determined by
550the current case table (@pxref{Case Tables}).
551@item [:word:]
552This matches any character that has word syntax (@pxref{Syntax Class
553Table}).
554@item [:xdigit:]
555This matches the hexadecimal digits: @samp{0} through @samp{9}, @samp{a}
556through @samp{f} and @samp{A} through @samp{F}.
557@end table
558
559@node Regexp Backslash
560@subsubsection Backslash Constructs in Regular Expressions
561
562 For the most part, @samp{\} followed by any character matches only
563that character. However, there are several exceptions: certain
564two-character sequences starting with @samp{\} that have special
565meanings. (The character after the @samp{\} in such a sequence is
566always ordinary when used on its own.) Here is a table of the special
567@samp{\} constructs.
7015aca4 568
969fe9b5 569@table @samp
7015aca4
RS
570@item \|
571@cindex @samp{|} in regexp
572@cindex regexp alternative
573specifies an alternative.
574Two regular expressions @var{a} and @var{b} with @samp{\|} in
575between form an expression that matches anything that either @var{a} or
576@var{b} matches.@refill
577
578Thus, @samp{foo\|bar} matches either @samp{foo} or @samp{bar}
579but no other string.@refill
580
581@samp{\|} applies to the largest possible surrounding expressions. Only a
582surrounding @samp{\( @dots{} \)} grouping can limit the grouping power of
583@samp{\|}.@refill
584
01913af2
RS
585If you need full backtracking capability to handle multiple uses of
586@samp{\|}, use the POSIX regular expression functions (@pxref{POSIX
587Regexps}).
7015aca4 588
2d06696f
RS
589@item \@{@var{m}\@}
590is a postfix operator that repeats the previous pattern exactly @var{m}
591times. Thus, @samp{x\@{5\@}} matches the string @samp{xxxxx}
592and nothing else. @samp{c[ad]\@{3\@}r} matches string such as
593@samp{caaar}, @samp{cdddr}, @samp{cadar}, and so on.
594
595@item \@{@var{m},@var{n}\@}
2a233172 596is a more general postfix operator that specifies repetition with a
2d06696f
RS
597minimum of @var{m} repeats and a maximum of @var{n} repeats. If @var{m}
598is omitted, the minimum is 0; if @var{n} is omitted, there is no
599maximum.
600
601For example, @samp{c[ad]\@{1,2\@}r} matches the strings @samp{car},
602@samp{cdr}, @samp{caar}, @samp{cadr}, @samp{cdar}, and @samp{cddr}, and
603nothing else.@*
604@samp{\@{0,1\@}} or @samp{\@{,1\@}} is equivalent to @samp{?}. @*
605@samp{\@{0,\@}} or @samp{\@{,\@}} is equivalent to @samp{*}. @*
606@samp{\@{1,\@}} is equivalent to @samp{+}.
607
7015aca4
RS
608@item \( @dots{} \)
609@cindex @samp{(} in regexp
610@cindex @samp{)} in regexp
611@cindex regexp grouping
612is a grouping construct that serves three purposes:
613
614@enumerate
615@item
9e2b495b
RS
616To enclose a set of @samp{\|} alternatives for other operations. Thus,
617the regular expression @samp{\(foo\|bar\)x} matches either @samp{foox}
618or @samp{barx}.
7015aca4
RS
619
620@item
1cd71ce0
RS
621To enclose a complicated expression for the postfix operators @samp{*},
622@samp{+} and @samp{?} to operate on. Thus, @samp{ba\(na\)*} matches
a9f0a989
RS
623@samp{ba}, @samp{bana}, @samp{banana}, @samp{bananana}, etc., with any
624number (zero or more) of @samp{na} strings.
7015aca4
RS
625
626@item
2d06696f
RS
627To record a matched substring for future reference with
628@samp{\@var{digit}} (see below).
7015aca4
RS
629@end enumerate
630
631This last application is not a consequence of the idea of a
2d06696f
RS
632parenthetical grouping; it is a separate feature that was assigned as a
633second meaning to the same @samp{\( @dots{} \)} construct because, in
a39c2e0d 634practice, there was usually no conflict between the two meanings. But
2d06696f
RS
635occasionally there is a conflict, and that led to the introduction of
636shy groups.
637
638@item \(?: @dots{} \)
639is the @dfn{shy group} construct. A shy group serves the first two
640purposes of an ordinary group (controlling the nesting of other
641operators), but it does not get a number, so you cannot refer back to
642its value with @samp{\@var{digit}}.
643
bcb6b6b8 644Shy groups are particularly useful for mechanically-constructed regular
2d06696f
RS
645expressions because they can be added automatically without altering the
646numbering of any ordinary, non-shy groups.
7015aca4
RS
647
648@item \@var{digit}
61cfa852 649matches the same text that matched the @var{digit}th occurrence of a
a5d0a32e 650grouping (@samp{\( @dots{} \)}) construct.
7015aca4 651
a5d0a32e
RS
652In other words, after the end of a group, the matcher remembers the
653beginning and end of the text matched by that group. Later on in the
654regular expression you can use @samp{\} followed by @var{digit} to
655match that same text, whatever it may have been.
7015aca4 656
a5d0a32e
RS
657The strings matching the first nine grouping constructs appearing in
658the entire regular expression passed to a search or matching function
659are assigned numbers 1 through 9 in the order that the open
660parentheses appear in the regular expression. So you can use
661@samp{\1} through @samp{\9} to refer to the text matched by the
662corresponding grouping constructs.
7015aca4
RS
663
664For example, @samp{\(.*\)\1} matches any newline-free string that is
665composed of two identical halves. The @samp{\(.*\)} matches the first
666half, which may be anything, but the @samp{\1} that follows must match
667the same exact text.
668
bcb6b6b8
LT
669If a @samp{\( @dots{} \)} construct matches more than once (which can
670happen, for instance, if it is followed by @samp{*}), only the last
671match is recorded.
672
a5d0a32e
RS
673If a particular grouping construct in the regular expression was never
674matched---for instance, if it appears inside of an alternative that
675wasn't used, or inside of a repetition that repeated zero times---then
676the corresponding @samp{\@var{digit}} construct never matches
677anything. To use an artificial example,, @samp{\(foo\(b*\)\|lose\)\2}
678cannot match @samp{lose}: the second alternative inside the larger
679group matches it, but then @samp{\2} is undefined and can't match
680anything. But it can match @samp{foobb}, because the first
681alternative matches @samp{foob} and @samp{\2} matches @samp{b}.
682
7015aca4
RS
683@item \w
684@cindex @samp{\w} in regexp
685matches any word-constituent character. The editor syntax table
686determines which characters these are. @xref{Syntax Tables}.
687
688@item \W
689@cindex @samp{\W} in regexp
61cfa852 690matches any character that is not a word constituent.
7015aca4
RS
691
692@item \s@var{code}
693@cindex @samp{\s} in regexp
694matches any character whose syntax is @var{code}. Here @var{code} is a
61cfa852 695character that represents a syntax code: thus, @samp{w} for word
7015aca4 696constituent, @samp{-} for whitespace, @samp{(} for open parenthesis,
f9f59935
RS
697etc. To represent whitespace syntax, use either @samp{-} or a space
698character. @xref{Syntax Class Table}, for a list of syntax codes and
699the characters that stand for them.
7015aca4
RS
700
701@item \S@var{code}
702@cindex @samp{\S} in regexp
703matches any character whose syntax is not @var{code}.
a8b5bbef
DL
704
705@item \c@var{c}
706matches any character whose category is @var{c}. Here @var{c} is a
707character that represents a category: thus, @samp{c} for Chinese
708characters or @samp{g} for Greek characters in the standard category
709table.
710
711@item \C@var{c}
712matches any character whose category is not @var{c}.
7015aca4
RS
713@end table
714
61cfa852 715 The following regular expression constructs match the empty string---that is,
7015aca4 716they don't use up any characters---but whether they match depends on the
bcb6b6b8
LT
717context. For all, the beginning and end of the accessible portion of
718the buffer are treated as if they were the actual beginning and end of
719the buffer.
7015aca4 720
969fe9b5 721@table @samp
7015aca4
RS
722@item \`
723@cindex @samp{\`} in regexp
724matches the empty string, but only at the beginning
725of the buffer or string being matched against.
726
727@item \'
728@cindex @samp{\'} in regexp
729matches the empty string, but only at the end of
730the buffer or string being matched against.
731
732@item \=
733@cindex @samp{\=} in regexp
734matches the empty string, but only at point.
735(This construct is not defined when matching against a string.)
736
737@item \b
738@cindex @samp{\b} in regexp
739matches the empty string, but only at the beginning or
740end of a word. Thus, @samp{\bfoo\b} matches any occurrence of
741@samp{foo} as a separate word. @samp{\bballs?\b} matches
742@samp{ball} or @samp{balls} as a separate word.@refill
743
bcb6b6b8 744@samp{\b} matches at the beginning or end of the buffer (or string)
1cd71ce0
RS
745regardless of what text appears next to it.
746
7015aca4
RS
747@item \B
748@cindex @samp{\B} in regexp
749matches the empty string, but @emph{not} at the beginning or
bcb6b6b8 750end of a word, nor at the beginning or end of the buffer (or string).
7015aca4
RS
751
752@item \<
753@cindex @samp{\<} in regexp
754matches the empty string, but only at the beginning of a word.
bcb6b6b8 755@samp{\<} matches at the beginning of the buffer (or string) only if a
1cd71ce0 756word-constituent character follows.
7015aca4
RS
757
758@item \>
759@cindex @samp{\>} in regexp
1cd71ce0 760matches the empty string, but only at the end of a word. @samp{\>}
bcb6b6b8
LT
761matches at the end of the buffer (or string) only if the contents end
762with a word-constituent character.
9a7e97c6
LT
763
764@item \_<
765@cindex @samp{\_<} in regexp
766matches the empty string, but only at the beginning of a symbol. A
767symbol is a sequence of one or more word or symbol constituent
768characters. @samp{\_<} matches at the beginning of the buffer (or
769string) only if a symbol-constituent character follows.
770
771@item \_>
772@cindex @samp{\_>} in regexp
773matches the empty string, but only at the end of a symbol. @samp{\_>}
774matches at the end of the buffer (or string) only if the contents end
775with a symbol-constituent character.
7015aca4
RS
776@end table
777
778@kindex invalid-regexp
779 Not every string is a valid regular expression. For example, a string
179a6f21
LT
780that ends inside a character alternative without terminating @samp{]}
781is invalid, and so is a string that ends with a single @samp{\}. If
7015aca4
RS
782an invalid regular expression is passed to any of the search functions,
783an @code{invalid-regexp} error is signaled.
784
7015aca4
RS
785@node Regexp Example
786@comment node-name, next, previous, up
787@subsection Complex Regexp Example
788
bcb6b6b8
LT
789 Here is a complicated regexp which was formerly used by Emacs to
790recognize the end of a sentence together with any whitespace that
45fa30b2
LT
791follows. (Nowadays Emacs uses a similar but more complex default
792regexp constructed by the function @code{sentence-end}.
793@xref{Standard Regexps}.)
7015aca4
RS
794
795 First, we show the regexp as a string in Lisp syntax to distinguish
796spaces from tab characters. The string constant begins and ends with a
797double-quote. @samp{\"} stands for a double-quote as part of the
798string, @samp{\\} for a backslash as part of the string, @samp{\t} for a
799tab and @samp{\n} for a newline.
800
801@example
bcb6b6b8 802"[.?!][]\"')@}]*\\($\\| $\\|\t\\|@ @ \\)[ \t\n]*"
7015aca4
RS
803@end example
804
969fe9b5 805@noindent
bcb6b6b8 806In contrast, if you evaluate this string, you will see the following:
7015aca4
RS
807
808@example
809@group
bcb6b6b8
LT
810"[.?!][]\"')@}]*\\($\\| $\\|\t\\|@ @ \\)[ \t\n]*"
811 @result{} "[.?!][]\"')@}]*\\($\\| $\\| \\|@ @ \\)[
7015aca4
RS
812]*"
813@end group
814@end example
815
816@noindent
817In this output, tab and newline appear as themselves.
818
819 This regular expression contains four parts in succession and can be
820deciphered as follows:
821
822@table @code
823@item [.?!]
969fe9b5
RS
824The first part of the pattern is a character alternative that matches
825any one of three characters: period, question mark, and exclamation
bcb6b6b8 826mark. The match must begin with one of these three characters. (This
45fa30b2
LT
827is one point where the new default regexp used by Emacs differs from
828the old. The new value also allows some non-@acronym{ASCII}
829characters that end a sentence without any following whitespace.)
7015aca4
RS
830
831@item []\"')@}]*
832The second part of the pattern matches any closing braces and quotation
833marks, zero or more of them, that may follow the period, question mark
834or exclamation mark. The @code{\"} is Lisp syntax for a double-quote in
835a string. The @samp{*} at the end indicates that the immediately
969fe9b5 836preceding regular expression (a character alternative, in this case) may be
7015aca4
RS
837repeated zero or more times.
838
7fd1911a 839@item \\($\\|@ $\\|\t\\|@ @ \\)
7015aca4 840The third part of the pattern matches the whitespace that follows the
f9f59935
RS
841end of a sentence: the end of a line (optionally with a space), or a
842tab, or two spaces. The double backslashes mark the parentheses and
843vertical bars as regular expression syntax; the parentheses delimit a
844group and the vertical bars separate alternatives. The dollar sign is
845used to match the end of a line.
7015aca4
RS
846
847@item [ \t\n]*
848Finally, the last part of the pattern matches any additional whitespace
849beyond the minimum needed to end a sentence.
850@end table
851
8241495d
RS
852@node Regexp Functions
853@subsection Regular Expression Functions
854
855 These functions operate on regular expressions.
856
857@defun regexp-quote string
858This function returns a regular expression whose only exact match is
859@var{string}. Using this regular expression in @code{looking-at} will
860succeed only if the next characters in the buffer are @var{string};
861using it in a search function will succeed if the text being searched
862contains @var{string}.
863
864This allows you to request an exact string match or search when calling
865a function that wants a regular expression.
866
867@example
868@group
869(regexp-quote "^The cat$")
870 @result{} "\\^The cat\\$"
871@end group
872@end example
873
874One use of @code{regexp-quote} is to combine an exact string match with
875context described as a regular expression. For example, this searches
876for the string that is the value of @var{string}, surrounded by
877whitespace:
878
879@example
880@group
881(re-search-forward
882 (concat "\\s-" (regexp-quote string) "\\s-"))
883@end group
884@end example
885@end defun
886
887@defun regexp-opt strings &optional paren
8241495d 888This function returns an efficient regular expression that will match
bcb6b6b8
LT
889any of the strings in the list @var{strings}. This is useful when you
890need to make matching or searching as fast as possible---for example,
891for Font Lock mode.
8241495d
RS
892
893If the optional argument @var{paren} is non-@code{nil}, then the
894returned regular expression is always enclosed by at least one
bcb6b6b8
LT
895parentheses-grouping construct. If @var{paren} is @code{words}, then
896that construct is additionally surrounded by @samp{\<} and @samp{\>}.
8241495d
RS
897
898This simplified definition of @code{regexp-opt} produces a
899regular expression which is equivalent to the actual value
900(but not as efficient):
901
902@example
903(defun regexp-opt (strings paren)
904 (let ((open-paren (if paren "\\(" ""))
905 (close-paren (if paren "\\)" "")))
906 (concat open-paren
907 (mapconcat 'regexp-quote strings "\\|")
908 close-paren)))
909@end example
910@end defun
911
912@defun regexp-opt-depth regexp
8241495d 913This function returns the total number of grouping constructs
bcb6b6b8
LT
914(parenthesized expressions) in @var{regexp}. (This does not include
915shy groups.)
8241495d
RS
916@end defun
917
7015aca4
RS
918@node Regexp Search
919@section Regular Expression Searching
920@cindex regular expression searching
921@cindex regexp searching
922@cindex searching for regexp
923
969fe9b5
RS
924 In GNU Emacs, you can search for the next match for a regular
925expression either incrementally or not. For incremental search
926commands, see @ref{Regexp Search, , Regular Expression Search, emacs,
927The GNU Emacs Manual}. Here we describe only the search functions
928useful in programs. The principal one is @code{re-search-forward}.
7015aca4 929
f9f59935
RS
930 These search functions convert the regular expression to multibyte if
931the buffer is multibyte; they convert the regular expression to unibyte
932if the buffer is unibyte. @xref{Text Representations}.
933
7015aca4
RS
934@deffn Command re-search-forward regexp &optional limit noerror repeat
935This function searches forward in the current buffer for a string of
936text that is matched by the regular expression @var{regexp}. The
937function skips over any amount of text that is not matched by
938@var{regexp}, and leaves point at the end of the first match found.
939It returns the new value of point.
940
5bb8ca2a
RS
941If @var{limit} is non-@code{nil}, it must be a position in the current
942buffer. It specifies the upper bound to the search. No match
943extending after that position is accepted.
7015aca4 944
5bb8ca2a
RS
945If @var{repeat} is supplied, it must be a positive number; the search
946is repeated that many times; each repetition starts at the end of the
4362c714
RS
947previous match. If all these successive searches succeed, the search
948succeeds, moving point and returning its new value. Otherwise the
949search fails. What @code{re-search-forward} does when the search
950fails depends on the value of @var{noerror}:
f9f59935 951
4362c714
RS
952@table @asis
953@item @code{nil}
954Signal a @code{search-failed} error.
955@item @code{t}
956Do nothing and return @code{nil}.
957@item anything else
958Move point to @var{limit} (or the end of the accessible portion of the
959buffer) and return @code{nil}.
960@end table
7015aca4 961
7015aca4
RS
962In the following example, point is initially before the @samp{T}.
963Evaluating the search call moves point to the end of that line (between
964the @samp{t} of @samp{hat} and the newline).
965
966@example
967@group
968---------- Buffer: foo ----------
969I read "@point{}The cat in the hat
970comes back" twice.
971---------- Buffer: foo ----------
972@end group
973
974@group
975(re-search-forward "[a-z]+" nil t 5)
976 @result{} 27
977
978---------- Buffer: foo ----------
979I read "The cat in the hat@point{}
980comes back" twice.
981---------- Buffer: foo ----------
982@end group
983@end example
984@end deffn
985
986@deffn Command re-search-backward regexp &optional limit noerror repeat
987This function searches backward in the current buffer for a string of
988text that is matched by the regular expression @var{regexp}, leaving
989point at the beginning of the first text found.
990
7fd1911a
RS
991This function is analogous to @code{re-search-forward}, but they are not
992simple mirror images. @code{re-search-forward} finds the match whose
993beginning is as close as possible to the starting point. If
994@code{re-search-backward} were a perfect mirror image, it would find the
995match whose end is as close as possible. However, in fact it finds the
bcb6b6b8
LT
996match whose beginning is as close as possible (and yet ends before the
997starting point). The reason for this is that matching a regular
998expression at a given spot always works from beginning to end, and
999starts at a specified beginning position.
7015aca4
RS
1000
1001A true mirror-image of @code{re-search-forward} would require a special
969fe9b5
RS
1002feature for matching regular expressions from end to beginning. It's
1003not worth the trouble of implementing that.
7015aca4
RS
1004@end deffn
1005
1006@defun string-match regexp string &optional start
1007This function returns the index of the start of the first match for
1008the regular expression @var{regexp} in @var{string}, or @code{nil} if
1009there is no match. If @var{start} is non-@code{nil}, the search starts
1010at that index in @var{string}.
1011
1012For example,
1013
1014@example
1015@group
1016(string-match
1017 "quick" "The quick brown fox jumped quickly.")
1018 @result{} 4
1019@end group
1020@group
1021(string-match
1022 "quick" "The quick brown fox jumped quickly." 8)
1023 @result{} 27
1024@end group
1025@end example
1026
1027@noindent
1028The index of the first character of the
1029string is 0, the index of the second character is 1, and so on.
1030
1031After this function returns, the index of the first character beyond
1032the match is available as @code{(match-end 0)}. @xref{Match Data}.
1033
1034@example
1035@group
1036(string-match
1037 "quick" "The quick brown fox jumped quickly." 8)
1038 @result{} 27
1039@end group
1040
1041@group
1042(match-end 0)
1043 @result{} 32
1044@end group
1045@end example
1046@end defun
1047
1048@defun looking-at regexp
1049This function determines whether the text in the current buffer directly
1050following point matches the regular expression @var{regexp}. ``Directly
1051following'' means precisely that: the search is ``anchored'' and it can
1052succeed only starting with the first character following point. The
1053result is @code{t} if so, @code{nil} otherwise.
1054
1055This function does not move point, but it updates the match data, which
1056you can access using @code{match-beginning} and @code{match-end}.
1057@xref{Match Data}.
1058
1059In this example, point is located directly before the @samp{T}. If it
1060were anywhere else, the result would be @code{nil}.
1061
1062@example
1063@group
1064---------- Buffer: foo ----------
1065I read "@point{}The cat in the hat
1066comes back" twice.
1067---------- Buffer: foo ----------
1068
1069(looking-at "The cat in the hat$")
1070 @result{} t
1071@end group
1072@end example
1073@end defun
1074
4d4d2d07
RS
1075@defun looking-back regexp &optional limit
1076This function returns @code{t} if @var{regexp} matches text before
1077point, ending at point, and @code{nil} otherwise.
1078
1079Because regular expression matching works only going forward, this is
1080implemented by searching backwards from point for a match that ends at
1081point. That can be quite slow if it has to search a long distance.
1082You can bound the time required by specifying @var{limit}, which says
1083not to search before @var{limit}. In this case, the match that is
1084found must begin at or after @var{limit}.
1085
1086@example
1087@group
1088---------- Buffer: foo ----------
1089I read "@point{}The cat in the hat
1090comes back" twice.
1091---------- Buffer: foo ----------
1092
1093(looking-back "read \"" 3)
1094 @result{} t
1095(looking-back "read \"" 4)
1096 @result{} nil
1097@end group
1098@end example
1099@end defun
1100
fe83e8de 1101@defvar search-spaces-regexp
65b65d26
RS
1102If this variable is non-@code{nil}, it should be a regular expression
1103that says how to search for whitespace. In that case, any group of
5bb8ca2a
RS
1104spaces in a regular expression being searched for stands for use of
1105this regular expression. However, spaces inside of constructs such as
1106@samp{[@dots{}]} and @samp{*}, @samp{+}, @samp{?} are not affected by
1107@code{search-spaces-regexp}.
1108
1109Since this variable affects all regular expression search and match
1110constructs, you should bind it temporarily for as small as possible
1111a part of the code.
65b65d26
RS
1112@end defvar
1113
22697dac
KH
1114@node POSIX Regexps
1115@section POSIX Regular Expression Searching
1116
1117 The usual regular expression functions do backtracking when necessary
1118to handle the @samp{\|} and repetition constructs, but they continue
1119this only until they find @emph{some} match. Then they succeed and
1120report the first match found.
1121
1122 This section describes alternative search functions which perform the
1123full backtracking specified by the POSIX standard for regular expression
1124matching. They continue backtracking until they have tried all
1125possibilities and found all matches, so they can report the longest
1126match, as required by POSIX. This is much slower, so use these
1127functions only when you really need the longest match.
1128
01913af2
RS
1129 The POSIX search and match functions do not properly support the
1130non-greedy repetition operators. This is because POSIX backtracking
1131conflicts with the semantics of non-greedy repetition.
1132
22697dac
KH
1133@defun posix-search-forward regexp &optional limit noerror repeat
1134This is like @code{re-search-forward} except that it performs the full
1135backtracking specified by the POSIX standard for regular expression
1136matching.
1137@end defun
1138
1139@defun posix-search-backward regexp &optional limit noerror repeat
1140This is like @code{re-search-backward} except that it performs the full
1141backtracking specified by the POSIX standard for regular expression
1142matching.
1143@end defun
1144
1145@defun posix-looking-at regexp
1146This is like @code{looking-at} except that it performs the full
1147backtracking specified by the POSIX standard for regular expression
1148matching.
1149@end defun
1150
1151@defun posix-string-match regexp string &optional start
1152This is like @code{string-match} except that it performs the full
1153backtracking specified by the POSIX standard for regular expression
1154matching.
1155@end defun
1156
7015aca4
RS
1157@node Match Data
1158@section The Match Data
1159@cindex match data
1160
3f63de1e 1161 Emacs keeps track of the start and end positions of the segments of
99543e8b
RS
1162text found during a search; this is called the @dfn{match data}.
1163Thanks to the match data, you can search for a complex pattern, such
1164as a date in a mail message, and then extract parts of the match under
1165control of the pattern.
7015aca4
RS
1166
1167 Because the match data normally describe the most recent search only,
1168you must be careful not to do another search inadvertently between the
1169search you wish to refer back to and the use of the match data. If you
1170can't avoid another intervening search, you must save and restore the
1171match data around it, to prevent it from being overwritten.
1172
1173@menu
969fe9b5 1174* Replacing Match:: Replacing a substring that was matched.
7015aca4
RS
1175* Simple Match Data:: Accessing single items of match data,
1176 such as where a particular subexpression started.
7015aca4
RS
1177* Entire Match Data:: Accessing the entire match data at once, as a list.
1178* Saving Match Data:: Saving and restoring the match data.
1179@end menu
1180
969fe9b5 1181@node Replacing Match
8241495d 1182@subsection Replacing the Text that Matched
969fe9b5 1183
99543e8b
RS
1184 This function replaces all or part of the text matched by the last
1185search. It works by means of the match data.
969fe9b5
RS
1186
1187@cindex case in replacements
1188@defun replace-match replacement &optional fixedcase literal string subexp
1189This function replaces the text in the buffer (or in @var{string}) that
1190was matched by the last search. It replaces that text with
1191@var{replacement}.
1192
1193If you did the last search in a buffer, you should specify @code{nil}
bcb6b6b8
LT
1194for @var{string} and make sure that the current buffer when you call
1195@code{replace-match} is the one in which you did the searching or
1196matching. Then @code{replace-match} does the replacement by editing
1197the buffer; it leaves point at the end of the replacement text, and
1198returns @code{t}.
969fe9b5
RS
1199
1200If you did the search in a string, pass the same string as @var{string}.
1201Then @code{replace-match} does the replacement by constructing and
1202returning a new string.
1203
2037b263
RS
1204If @var{fixedcase} is non-@code{nil}, then @code{replace-match} uses
1205the replacement text without case conversion; otherwise, it converts
1206the replacement text depending upon the capitalization of the text to
1207be replaced. If the original text is all upper case, this converts
1208the replacement text to upper case. If all words of the original text
1209are capitalized, this capitalizes all the words of the replacement
1210text. If all the words are one-letter and they are all upper case,
1211they are treated as capitalized words rather than all-upper-case
1212words.
969fe9b5 1213
969fe9b5
RS
1214If @var{literal} is non-@code{nil}, then @var{replacement} is inserted
1215exactly as it is, the only alterations being case changes as needed.
1216If it is @code{nil} (the default), then the character @samp{\} is treated
1217specially. If a @samp{\} appears in @var{replacement}, then it must be
1218part of one of the following sequences:
1219
1220@table @asis
1221@item @samp{\&}
1222@cindex @samp{&} in replacement
1223@samp{\&} stands for the entire text being replaced.
1224
1225@item @samp{\@var{n}}
1226@cindex @samp{\@var{n}} in replacement
1227@samp{\@var{n}}, where @var{n} is a digit, stands for the text that
1228matched the @var{n}th subexpression in the original regexp.
1229Subexpressions are those expressions grouped inside @samp{\(@dots{}\)}.
bcb6b6b8 1230If the @var{n}th subexpression never matched, an empty string is substituted.
969fe9b5
RS
1231
1232@item @samp{\\}
1233@cindex @samp{\} in replacement
1234@samp{\\} stands for a single @samp{\} in the replacement text.
1235@end table
1236
2037b263
RS
1237These substitutions occur after case conversion, if any,
1238so the strings they substitute are never case-converted.
1239
969fe9b5
RS
1240If @var{subexp} is non-@code{nil}, that says to replace just
1241subexpression number @var{subexp} of the regexp that was matched, not
1242the entire match. For example, after matching @samp{foo \(ba*r\)},
1243calling @code{replace-match} with 1 as @var{subexp} means to replace
1244just the text that matched @samp{\(ba*r\)}.
1245@end defun
1246
7015aca4
RS
1247@node Simple Match Data
1248@subsection Simple Match Data Access
1249
22697dac 1250 This section explains how to use the match data to find out what was
87bf725e 1251matched by the last search or match operation, if it succeeded.
22697dac
KH
1252
1253 You can ask about the entire matching text, or about a particular
1254parenthetical subexpression of a regular expression. The @var{count}
1255argument in the functions below specifies which. If @var{count} is
1256zero, you are asking about the entire match. If @var{count} is
1257positive, it specifies which subexpression you want.
1258
1259 Recall that the subexpressions of a regular expression are those
1260expressions grouped with escaped parentheses, @samp{\(@dots{}\)}. The
1261@var{count}th subexpression is found by counting occurrences of
1262@samp{\(} from the beginning of the whole regular expression. The first
1263subexpression is numbered 1, the second 2, and so on. Only regular
1264expressions can have subexpressions---after a simple string search, the
1265only information available is about the entire match.
1266
5345f90d
EZ
1267 Every successful search sets the match data. Therefore, you should
1268query the match data immediately after searching, before calling any
1269other function that might perform another search. Alternatively, you
1270may save and restore the match data (@pxref{Saving Match Data}) around
1271the call to functions that could perform another search.
1272
a9f0a989
RS
1273 A search which fails may or may not alter the match data. In the
1274past, a failing search did not do this, but we may change it in the
87bf725e
RS
1275future. So don't try to rely on the value of the match data after
1276a failing search.
a9f0a989 1277
22697dac
KH
1278@defun match-string count &optional in-string
1279This function returns, as a string, the text matched in the last search
1280or match operation. It returns the entire text if @var{count} is zero,
1281or just the portion corresponding to the @var{count}th parenthetical
a5d0a32e 1282subexpression, if @var{count} is positive.
22697dac
KH
1283
1284If the last such operation was done against a string with
1285@code{string-match}, then you should pass the same string as the
969fe9b5 1286argument @var{in-string}. After a buffer search or match,
22697dac
KH
1287you should omit @var{in-string} or pass @code{nil} for it; but you
1288should make sure that the current buffer when you call
1289@code{match-string} is the one in which you did the searching or
1290matching.
a5d0a32e
RS
1291
1292The value is @code{nil} if @var{count} is out of range, or for a
1293subexpression inside a @samp{\|} alternative that wasn't used or a
1294repetition that repeated zero times.
22697dac 1295@end defun
7015aca4 1296
79ddc9c9 1297@defun match-string-no-properties count &optional in-string
f9f59935
RS
1298This function is like @code{match-string} except that the result
1299has no text properties.
1300@end defun
1301
7015aca4
RS
1302@defun match-beginning count
1303This function returns the position of the start of text matched by the
1304last regular expression searched for, or a subexpression of it.
1305
7fd1911a 1306If @var{count} is zero, then the value is the position of the start of
eaac2be1 1307the entire match. Otherwise, @var{count} specifies a subexpression in
969fe9b5 1308the regular expression, and the value of the function is the starting
22697dac
KH
1309position of the match for that subexpression.
1310
1311The value is @code{nil} for a subexpression inside a @samp{\|}
a5d0a32e 1312alternative that wasn't used or a repetition that repeated zero times.
7015aca4
RS
1313@end defun
1314
1315@defun match-end count
22697dac
KH
1316This function is like @code{match-beginning} except that it returns the
1317position of the end of the match, rather than the position of the
1318beginning.
7015aca4
RS
1319@end defun
1320
1321 Here is an example of using the match data, with a comment showing the
1322positions within the text:
1323
1324@example
1325@group
1326(string-match "\\(qu\\)\\(ick\\)"
1327 "The quick fox jumped quickly.")
177c0ea7 1328 ;0123456789
7015aca4
RS
1329 @result{} 4
1330@end group
1331
22697dac
KH
1332@group
1333(match-string 0 "The quick fox jumped quickly.")
1334 @result{} "quick"
1335(match-string 1 "The quick fox jumped quickly.")
1336 @result{} "qu"
1337(match-string 2 "The quick fox jumped quickly.")
1338 @result{} "ick"
1339@end group
1340
7015aca4
RS
1341@group
1342(match-beginning 1) ; @r{The beginning of the match}
1343 @result{} 4 ; @r{with @samp{qu} is at index 4.}
1344@end group
1345
1346@group
1347(match-beginning 2) ; @r{The beginning of the match}
1348 @result{} 6 ; @r{with @samp{ick} is at index 6.}
1349@end group
1350
1351@group
1352(match-end 1) ; @r{The end of the match}
1353 @result{} 6 ; @r{with @samp{qu} is at index 6.}
1354
1355(match-end 2) ; @r{The end of the match}
1356 @result{} 9 ; @r{with @samp{ick} is at index 9.}
1357@end group
1358@end example
1359
1360 Here is another example. Point is initially located at the beginning
1361of the line. Searching moves point to between the space and the word
1362@samp{in}. The beginning of the entire match is at the 9th character of
1363the buffer (@samp{T}), and the beginning of the match for the first
1364subexpression is at the 13th character (@samp{c}).
1365
1366@example
1367@group
1368(list
1369 (re-search-forward "The \\(cat \\)")
1370 (match-beginning 0)
1371 (match-beginning 1))
7fd1911a 1372 @result{} (9 9 13)
7015aca4
RS
1373@end group
1374
1375@group
1376---------- Buffer: foo ----------
1377I read "The cat @point{}in the hat comes back" twice.
1378 ^ ^
1379 9 13
1380---------- Buffer: foo ----------
1381@end group
1382@end example
1383
1384@noindent
1385(In this case, the index returned is a buffer position; the first
1386character of the buffer counts as 1.)
1387
7015aca4
RS
1388@node Entire Match Data
1389@subsection Accessing the Entire Match Data
1390
1391 The functions @code{match-data} and @code{set-match-data} read or
1392write the entire match data, all at once.
1393
4e370af2 1394@defun match-data &optional integers reuse reseat
8135a25a
RS
1395This function returns a list of positions (markers or integers) that
1396record all the information on what text the last search matched.
1397Element zero is the position of the beginning of the match for the
1398whole expression; element one is the position of the end of the match
1399for the expression. The next two elements are the positions of the
1400beginning and end of the match for the first subexpression, and so on.
1401In general, element
37680279 1402@ifnottex
7015aca4 1403number 2@var{n}
37680279 1404@end ifnottex
7015aca4
RS
1405@tex
1406number {\mathsurround=0pt $2n$}
1407@end tex
1408corresponds to @code{(match-beginning @var{n})}; and
1409element
37680279 1410@ifnottex
7015aca4 1411number 2@var{n} + 1
37680279 1412@end ifnottex
7015aca4
RS
1413@tex
1414number {\mathsurround=0pt $2n+1$}
1415@end tex
1416corresponds to @code{(match-end @var{n})}.
1417
8135a25a
RS
1418Normally all the elements are markers or @code{nil}, but if
1419@var{integers} is non-@code{nil}, that means to use integers instead
1420of markers. (In that case, the buffer itself is appended as an
1421additional element at the end of the list, to facilitate complete
1422restoration of the match data.) If the last match was done on a
1423string with @code{string-match}, then integers are always used,
1424since markers can't point into a string.
bcb6b6b8
LT
1425
1426If @var{reuse} is non-@code{nil}, it should be a list. In that case,
1427@code{match-data} stores the match data in @var{reuse}. That is,
1428@var{reuse} is destructively modified. @var{reuse} does not need to
1429have the right length. If it is not long enough to contain the match
1430data, it is extended. If it is too long, the length of @var{reuse}
1431stays the same, but the elements that were not used are set to
8135a25a
RS
1432@code{nil}. The purpose of this feature is to reduce the need for
1433garbage collection.
7015aca4 1434
4e370af2 1435If @var{reseat} is non-@code{nil}, all markers on the @var{reuse} list
68be435e 1436are reseated to point to nowhere.
4e370af2 1437
7015aca4
RS
1438As always, there must be no possibility of intervening searches between
1439the call to a search function and the call to @code{match-data} that is
1440intended to access the match data for that search.
1441
1442@example
1443@group
1444(match-data)
1445 @result{} (#<marker at 9 in foo>
1446 #<marker at 17 in foo>
1447 #<marker at 13 in foo>
1448 #<marker at 17 in foo>)
1449@end group
1450@end example
1451@end defun
1452
4e370af2 1453@defun set-match-data match-list &optional reseat
7015aca4
RS
1454This function sets the match data from the elements of @var{match-list},
1455which should be a list that was the value of a previous call to
3ab8acb9
RS
1456@code{match-data}. (More precisely, anything that has the same format
1457will work.)
7015aca4
RS
1458
1459If @var{match-list} refers to a buffer that doesn't exist, you don't get
1460an error; that sets the match data in a meaningless but harmless way.
1461
4e370af2 1462If @var{reseat} is non-@code{nil}, all markers on the @var{match-list} list
68be435e 1463are reseated to point to nowhere.
4e370af2 1464
7015aca4 1465@findex store-match-data
969fe9b5 1466@code{store-match-data} is a semi-obsolete alias for @code{set-match-data}.
7015aca4
RS
1467@end defun
1468
1469@node Saving Match Data
1470@subsection Saving and Restoring the Match Data
1471
d1280259
RS
1472 When you call a function that may do a search, you may need to save
1473and restore the match data around that call, if you want to preserve the
1474match data from an earlier search for later use. Here is an example
1475that shows the problem that arises if you fail to save the match data:
7015aca4
RS
1476
1477@example
1478@group
1479(re-search-forward "The \\(cat \\)")
1480 @result{} 48
1481(foo) ; @r{Perhaps @code{foo} does}
1482 ; @r{more searching.}
1483(match-end 0)
1484 @result{} 61 ; @r{Unexpected result---not 48!}
1485@end group
1486@end example
1487
d1280259 1488 You can save and restore the match data with @code{save-match-data}:
7015aca4 1489
bfe721d1 1490@defmac save-match-data body@dots{}
1911e6e5 1491This macro executes @var{body}, saving and restoring the match
bcb6b6b8
LT
1492data around it. The return value is the value of the last form in
1493@var{body}.
bfe721d1 1494@end defmac
7015aca4 1495
969fe9b5
RS
1496 You could use @code{set-match-data} together with @code{match-data} to
1497imitate the effect of the special form @code{save-match-data}. Here is
1498how:
7015aca4
RS
1499
1500@example
1501@group
1502(let ((data (match-data)))
1503 (unwind-protect
f9f59935 1504 @dots{} ; @r{Ok to change the original match data.}
7015aca4
RS
1505 (set-match-data data)))
1506@end group
1507@end example
1508
d1280259
RS
1509 Emacs automatically saves and restores the match data when it runs
1510process filter functions (@pxref{Filter Functions}) and process
1511sentinels (@pxref{Sentinels}).
1512
7015aca4
RS
1513@ignore
1514 Here is a function which restores the match data provided the buffer
1515associated with it still exists.
1516
1517@smallexample
1518@group
1519(defun restore-match-data (data)
1520@c It is incorrect to split the first line of a doc string.
1521@c If there's a problem here, it should be solved in some other way.
1522 "Restore the match data DATA unless the buffer is missing."
1523 (catch 'foo
1524 (let ((d data))
1525@end group
1526 (while d
1527 (and (car d)
1528 (null (marker-buffer (car d)))
1529@group
1530 ;; @file{match-data} @r{buffer is deleted.}
1531 (throw 'foo nil))
1532 (setq d (cdr d)))
1533 (set-match-data data))))
1534@end group
1535@end smallexample
1536@end ignore
1537
99543e8b
RS
1538@node Search and Replace
1539@section Search and Replace
1540@cindex replacement
7015aca4 1541
99543e8b
RS
1542 If you want to find all matches for a regexp in part of the buffer,
1543and replace them, the best way is to write an explicit loop using
1544@code{re-search-forward} and @code{replace-match}, like this:
7015aca4 1545
99543e8b
RS
1546@example
1547(while (re-search-forward "foo[ \t]+bar" nil t)
1548 (replace-match "foobar"))
1549@end example
7015aca4 1550
99543e8b
RS
1551@noindent
1552@xref{Replacing Match,, Replacing the Text that Matched}, for a
1553description of @code{replace-match}.
7015aca4 1554
99543e8b
RS
1555 However, replacing matches in a string is more complex, especially
1556if you want to do it efficiently. So Emacs provides a function to do
1557this.
7fd1911a 1558
99543e8b
RS
1559@defun replace-regexp-in-string regexp rep string &optional fixedcase literal subexp start
1560This function copies @var{string} and searches it for matches for
1561@var{regexp}, and replaces them with @var{rep}. It returns the
1562modified copy. If @var{start} is non-@code{nil}, the search for
1563matches starts at that index in @var{string}, so matches starting
1564before that index are not changed.
7015aca4 1565
99543e8b
RS
1566This function uses @code{replace-match} to do the replacement, and it
1567passes the optional arguments @var{fixedcase}, @var{literal} and
1568@var{subexp} along to @code{replace-match}.
7015aca4 1569
99543e8b
RS
1570Instead of a string, @var{rep} can be a function. In that case,
1571@code{replace-regexp-in-string} calls @var{rep} for each match,
1572passing the text of the match as its sole argument. It collects the
1573value @var{rep} returns and passes that to @code{replace-match} as the
1574replacement string. The match-data at this point are the result
1575of matching @var{regexp} against a substring of @var{string}.
1576@end defun
1577
1578 If you want to write a command along the lines of @code{query-replace},
1579you can use @code{perform-replace} to do the work.
1580
1581@defun perform-replace from-string replacements query-flag regexp-flag delimited-flag &optional repeat-count map start end
1582This function is the guts of @code{query-replace} and related
1583commands. It searches for occurrences of @var{from-string} in the
1584text between positions @var{start} and @var{end} and replaces some or
1585all of them. If @var{start} is @code{nil} (or omitted), point is used
1586instead, and the end of the buffer's accessible portion is used for
1587@var{end}.
1588
1589If @var{query-flag} is @code{nil}, it replaces all
1590occurrences; otherwise, it asks the user what to do about each one.
1591
1592If @var{regexp-flag} is non-@code{nil}, then @var{from-string} is
1593considered a regular expression; otherwise, it must match literally. If
1594@var{delimited-flag} is non-@code{nil}, then only replacements
1595surrounded by word boundaries are considered.
1596
1597The argument @var{replacements} specifies what to replace occurrences
1598with. If it is a string, that string is used. It can also be a list of
1599strings, to be used in cyclic order.
1600
1601If @var{replacements} is a cons cell, @code{(@var{function}
1602. @var{data})}, this means to call @var{function} after each match to
1603get the replacement text. This function is called with two arguments:
1604@var{data}, and the number of replacements already made.
1605
1606If @var{repeat-count} is non-@code{nil}, it should be an integer. Then
1607it specifies how many times to use each of the strings in the
1608@var{replacements} list before advancing cyclically to the next one.
1609
1610If @var{from-string} contains upper-case letters, then
1611@code{perform-replace} binds @code{case-fold-search} to @code{nil}, and
1612it uses the @code{replacements} without altering the case of them.
1613
1614Normally, the keymap @code{query-replace-map} defines the possible
1615user responses for queries. The argument @var{map}, if
1616non-@code{nil}, specifies a keymap to use instead of
1617@code{query-replace-map}.
1618@end defun
1619
1620@defvar query-replace-map
1621This variable holds a special keymap that defines the valid user
1622responses for @code{perform-replace} and the commands that use it, as
1623well as @code{y-or-n-p} and @code{map-y-or-n-p}. This map is unusual
1624in two ways:
1625
1626@itemize @bullet
1627@item
1628The ``key bindings'' are not commands, just symbols that are meaningful
1629to the functions that use this map.
1630
1631@item
1632Prefix keys are not supported; each key binding must be for a
1633single-event key sequence. This is because the functions don't use
1634@code{read-key-sequence} to get the input; instead, they read a single
1635event and look it up ``by hand.''
1636@end itemize
7015aca4
RS
1637@end defvar
1638
99543e8b
RS
1639Here are the meaningful ``bindings'' for @code{query-replace-map}.
1640Several of them are meaningful only for @code{query-replace} and
1641friends.
1642
1643@table @code
1644@item act
1645Do take the action being considered---in other words, ``yes.''
1646
1647@item skip
1648Do not take action for this question---in other words, ``no.''
1649
1650@item exit
1651Answer this question ``no,'' and give up on the entire series of
1652questions, assuming that the answers will be ``no.''
1653
1654@item act-and-exit
1655Answer this question ``yes,'' and give up on the entire series of
1656questions, assuming that subsequent answers will be ``no.''
1657
1658@item act-and-show
1659Answer this question ``yes,'' but show the results---don't advance yet
1660to the next question.
1661
1662@item automatic
1663Answer this question and all subsequent questions in the series with
1664``yes,'' without further user interaction.
1665
1666@item backup
1667Move back to the previous place that a question was asked about.
1668
1669@item edit
1670Enter a recursive edit to deal with this question---instead of any
1671other action that would normally be taken.
1672
1673@item delete-and-edit
1674Delete the text being considered, then enter a recursive edit to replace
1675it.
1676
1677@item recenter
1678Redisplay and center the window, then ask the same question again.
1679
1680@item quit
1681Perform a quit right away. Only @code{y-or-n-p} and related functions
1682use this answer.
1683
1684@item help
1685Display some help, then ask again.
1686@end table
1687
7015aca4
RS
1688@node Standard Regexps
1689@section Standard Regular Expressions Used in Editing
1690@cindex regexps used standardly in editing
1691@cindex standard regexps used in editing
1692
1693 This section describes some variables that hold regular expressions
1694used for certain purposes in editing:
1695
1696@defvar page-delimiter
969fe9b5
RS
1697This is the regular expression describing line-beginnings that separate
1698pages. The default value is @code{"^\014"} (i.e., @code{"^^L"} or
1699@code{"^\C-l"}); this matches a line that starts with a formfeed
1700character.
7015aca4
RS
1701@end defvar
1702
22697dac
KH
1703 The following two regular expressions should @emph{not} assume the
1704match always starts at the beginning of a line; they should not use
1705@samp{^} to anchor the match. Most often, the paragraph commands do
1706check for a match only at the beginning of a line, which means that
bfe721d1
KH
1707@samp{^} would be superfluous. When there is a nonzero left margin,
1708they accept matches that start after the left margin. In that case, a
1709@samp{^} would be incorrect. However, a @samp{^} is harmless in modes
1710where a left margin is never used.
22697dac 1711
7015aca4
RS
1712@defvar paragraph-separate
1713This is the regular expression for recognizing the beginning of a line
1714that separates paragraphs. (If you change this, you may have to
7fd1911a 1715change @code{paragraph-start} also.) The default value is
22697dac
KH
1716@w{@code{"[@ \t\f]*$"}}, which matches a line that consists entirely of
1717spaces, tabs, and form feeds (after its left margin).
7015aca4
RS
1718@end defvar
1719
1720@defvar paragraph-start
1721This is the regular expression for recognizing the beginning of a line
1722that starts @emph{or} separates paragraphs. The default value is
bcb6b6b8
LT
1723@w{@code{"\f\\|[ \t]*$"}}, which matches a line containing only
1724whitespace or starting with a form feed (after its left margin).
7015aca4
RS
1725@end defvar
1726
1727@defvar sentence-end
45fa30b2
LT
1728If non-@code{nil}, the value should be a regular expression describing
1729the end of a sentence, including the whitespace following the
1730sentence. (All paragraph boundaries also end sentences, regardless.)
1731
1732If the value is @code{nil}, the default, then the function
1733@code{sentence-end} has to construct the regexp. That is why you
1734should always call the function @code{sentence-end} to obtain the
1735regexp to be used to recognize the end of a sentence.
7015aca4 1736@end defvar
ab5796a9 1737
45fa30b2
LT
1738@defun sentence-end
1739This function returns the value of the variable @code{sentence-end},
1740if non-@code{nil}. Otherwise it returns a default value based on the
1741values of the variables @code{sentence-end-double-space}
1742(@pxref{Definition of sentence-end-double-space}),
1743@code{sentence-end-without-period} and
1744@code{sentence-end-without-space}.
1745@end defun
1746
ab5796a9
MB
1747@ignore
1748 arch-tag: c2573ca2-18aa-4839-93b8-924043ef831f
1749@end ignore