From 4848bdf98b8579a1e704441f600d607ed6941024 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 22 Jun 2023 08:32:16 +0300 Subject: [PATCH] ; Minor fixes of recently-installed regexp documentation changes * doc/emacs/search.texi (Regexps): * doc/lispref/searching.texi (Regexp Special): Keep the old terminology as "a.k.a.". (Char Classes, POSIX Regexps, POSIX Regexps): Add cross-references to where "bracket expression" is defined. (Bug#64128) --- doc/emacs/search.texi | 3 +- doc/lispref/searching.texi | 65 ++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 2a816221235..e8e79888ed8 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -1037,7 +1037,8 @@ starting at the first @samp{a}, it does. @cindex set of alternative characters, in regular expressions @cindex character set, in regular expressions @item @kbd{[ @dots{} ]} -is a @dfn{bracket expression}, which matches one of a set of characters. +is a @dfn{bracket expression} (a.k.a.@: @dfn{set of alternative +characters}), which matches one of a set of characters. In the simplest case, the characters between the two brackets are what this set can match. Thus, @samp{[ad]} matches either one @samp{a} or diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index 7c9893054d9..a0289d1f3cd 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi @@ -375,11 +375,13 @@ permits the whole expression to match is @samp{d}.) @item @samp{[ @dots{} ]} @cindex bracket expression (in regexp) +@cindex character alternative (in regexp) @cindex @samp{[} in regexp @cindex @samp{]} in regexp -is a @dfn{bracket expression}, which begins with @samp{[} and is -terminated by @samp{]}. In the simplest case, the characters between -the two brackets are what this bracket expression can match. +is a @dfn{bracket expression} (a.k.a.@: @dfn{character alternative}), +which begins with @samp{[} and is terminated by @samp{]}. In the +simplest case, the characters between the two brackets are what this +bracket expression can match. Thus, @samp{[ad]} matches either one @samp{a} or one @samp{d}, and @samp{[ad]*} matches any string composed of just @samp{a}s and @samp{d}s @@ -478,10 +480,10 @@ style; and although @samp{[*--]} is valid, @samp{[*+,-]} is clearer. @item @samp{[^ @dots{} ]} @cindex @samp{^} in regexp -@samp{[^} begins a @dfn{complemented bracket expression}. This -matches any character except the ones specified. Thus, -@samp{[^a-z0-9A-Z]} matches all characters @emph{except} ASCII letters and -digits. +@samp{[^} begins a @dfn{complemented bracket expression}, or +@dfn{complemented character alternative}. This matches any character +except the ones specified. Thus, @samp{[^a-z0-9A-Z]} matches all +characters @emph{except} ASCII letters and digits. @samp{^} is not special in a bracket expression unless it is the first character. The character following the @samp{^} is treated as if it @@ -588,13 +590,13 @@ an unquoted @samp{[} is special again and a @samp{]} not. @cindex alpha character class, regexp @cindex xdigit character class, regexp - Below is a table of the classes you can use in a bracket -expression, and what they mean. Note that the @samp{[} and @samp{]} -characters that enclose the class name are part of the name, so a -regular expression using these classes needs one more pair of -brackets. For example, a regular expression matching a sequence of -one or more letters and digits would be @samp{[[:alnum:]]+}, not -@samp{[:alnum:]+}. + Below is a table of the classes you can use in a bracket expression +(@pxref{Regexp Special, bracket expression}), and what they mean. +Note that the @samp{[} and @samp{]} characters that enclose the class +name are part of the name, so a regular expression using these classes +needs one more pair of brackets. For example, a regular expression +matching a sequence of one or more letters and digits would be +@samp{[[:alnum:]]+}, not @samp{[:alnum:]+}. @table @samp @item [:ascii:] @@ -2993,6 +2995,24 @@ POSIX does not define how other BRE escapes behave; for example, GNU @command{grep} treats @samp{\|} like Emacs does, but does not support all the Emacs escapes. +@item +In POSIX BREs, it is an implementation option whether @samp{^} is special +after @samp{\(}; GNU @command{grep} treats it like Emacs does. +In POSIX EREs, @samp{^} is always special outside of bracket expressions, +which means the ERE @samp{x^} never matches. +In Emacs regular expressions, @samp{^} is special only at the +beginning of the regular expression, or after @samp{\(}, @samp{\(?:} +or @samp{\|}. + +@item +In POSIX BREs, it is an implementation option whether @samp{$} is +special before @samp{\)}; GNU @command{grep} treats it like Emacs +does. In POSIX EREs, @samp{$} is always special outside of bracket +expressions (@pxref{Regexp Special, bracket expressions}), which means +the ERE @samp{$x} never matches. In Emacs regular expressions, +@samp{$} is special only at the end of the regular expression, or +before @samp{\)} or @samp{\|}. + @item In POSIX EREs @samp{@{}, @samp{(} and @samp{|} are special, and @samp{)} is special when matched with a preceding @samp{(}. @@ -3005,23 +3025,6 @@ POSIX does not define how other ERE escapes behave; for example, GNU @samp{grep -E} treats @samp{\1} like Emacs does, but does not support all the Emacs escapes. -@item -In POSIX BREs, it is an implementation option whether @samp{^} is special -after @samp{\(}; GNU @command{grep} treats it like Emacs does. -In POSIX EREs, @samp{^} is always special outside of bracket expressions, -which means the ERE @samp{x^} never matches. -In Emacs regular expressions, @samp{^} is special only at the -beginning of the regular expression, or after @samp{\(}, @samp{\(?:} -or @samp{\|}. - -@item -In POSIX BREs, it is an implementation option whether @samp{$} is special -before @samp{\)}; GNU @command{grep} treats it like Emacs does. -In POSIX EREs, @samp{$} is always special outside of bracket expressions, -which means the ERE @samp{$x} never matches. -In Emacs regular expressions, @samp{$} is special only at the -end of the regular expression, or before @samp{\)} or @samp{\|}. - @item In POSIX BREs and EREs, undefined results are produced by repetition operators at the start of a regular expression or subexpression -- 2.39.2