maint: enable sc_prohibit_cloexec_without_use
[gnulib/ericb.git] / doc / regexprops-generic.texi
blobbdd7807534b950f9b3216e7bdc19ba9c2e0d0f05
1 @c Copyright (C) 1994, 1996, 1998, 2000-2001, 2003-2007, 2009-2012 Free
2 @c Software Foundation, Inc.
3 @c
4 @c Permission is granted to copy, distribute and/or modify this document
5 @c under the terms of the GNU Free Documentation License, Version 1.3 or
6 @c any later version published by the Free Software Foundation; with no
7 @c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
8 @c Texts.  A copy of the license is included in the ``GNU Free
9 @c Documentation License'' file as part of this distribution.
11 @c this regular expression description is for: generic
13 @menu
14 * awk regular expression syntax::
15 * egrep regular expression syntax::
16 * ed regular expression syntax::
17 * emacs regular expression syntax::
18 * gnu-awk regular expression syntax::
19 * grep regular expression syntax::
20 * posix-awk regular expression syntax::
21 * posix-basic regular expression syntax::
22 * posix-egrep regular expression syntax::
23 * posix-extended regular expression syntax::
24 * posix-minimal-basic regular expression syntax::
25 * sed regular expression syntax::
26 @end menu
28 @node awk regular expression syntax
29 @subsection @samp{awk} regular expression syntax
32 The character @samp{.} matches any single character except the null character.
35 @table @samp
37 @item +
38 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
39 @item ?
40 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
41 @item \+
42 matches a @samp{+}
43 @item \?
44 matches a @samp{?}.
45 @end table
48 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are invalid.  Within square brackets, @samp{\} can be used to quote the following character.  Character classes are not supported, so for example you would need to use @samp{[0-9]} instead of @samp{[[:digit:]]}.
50 GNU extensions are not supported and so @samp{\w}, @samp{\W}, @samp{\<}, @samp{\>}, @samp{\b}, @samp{\B}, @samp{\`}, and @samp{\'} match @samp{w}, @samp{W}, @samp{<}, @samp{>}, @samp{b}, @samp{B}, @samp{`}, and @samp{'} respectively.
52 Grouping is performed with parentheses @samp{()}.  An unmatched @samp{)} matches just itself.  A backslash followed by a digit matches that digit.
54 The alternation operator is @samp{|}.
56 The characters @samp{^} and @samp{$} always represent the beginning and end of a string respectively, except within square brackets.  Within brackets, @samp{^} can be used to invert the membership of the character class being specified.
58 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except:
59 @enumerate
61 @item At the beginning of a regular expression
63 @item After an open-group, signified by
64 @samp{(}
65 @item After the alternation operator @samp{|}
67 @end enumerate
72 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
75 @node egrep regular expression syntax
76 @subsection @samp{egrep} regular expression syntax
79 The character @samp{.} matches any single character except newline.
82 @table @samp
84 @item +
85 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
86 @item ?
87 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
88 @item \+
89 matches a @samp{+}
90 @item \?
91 matches a @samp{?}.
92 @end table
95 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are ignored.  Within square brackets, @samp{\} is taken literally.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.  Non-matching lists @samp{[^@dots{}]} do not ever match newline.
97 GNU extensions are supported:
98 @enumerate
100 @item @samp{\w} matches a character within a word
102 @item @samp{\W} matches a character which is not within a word
104 @item @samp{\<} matches the beginning of a word
106 @item @samp{\>} matches the end of a word
108 @item @samp{\b} matches a word boundary
110 @item @samp{\B} matches characters which are not a word boundary
112 @item @samp{\`} matches the beginning of the whole input
114 @item @samp{\'} matches the end of the whole input
116 @end enumerate
119 Grouping is performed with parentheses @samp{()}.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{(}.
121 The alternation operator is @samp{|}.
123 The characters @samp{^} and @samp{$} always represent the beginning and end of a string respectively, except within square brackets.  Within brackets, @samp{^} can be used to invert the membership of the character class being specified.
125 The characters @samp{*}, @samp{+} and @samp{?} are special anywhere in a regular expression.
129 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
132 @node ed regular expression syntax
133 @subsection @samp{ed} regular expression syntax
136 The character @samp{.} matches any single character except the null character.
139 @table @samp
141 @item \+
142 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
143 @item \?
144 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
145 @item + and ?
146 match themselves.
147 @end table
150 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are invalid.  Within square brackets, @samp{\} is taken literally.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.
152 GNU extensions are supported:
153 @enumerate
155 @item @samp{\w} matches a character within a word
157 @item @samp{\W} matches a character which is not within a word
159 @item @samp{\<} matches the beginning of a word
161 @item @samp{\>} matches the end of a word
163 @item @samp{\b} matches a word boundary
165 @item @samp{\B} matches characters which are not a word boundary
167 @item @samp{\`} matches the beginning of the whole input
169 @item @samp{\'} matches the end of the whole input
171 @end enumerate
174 Grouping is performed with backslashes followed by parentheses @samp{\(}, @samp{\)}.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{\(}.
176 The alternation operator is @samp{\|}.
178 The character @samp{^} only represents the beginning of a string when it appears:
179 @enumerate
181 @item
182 At the beginning of a regular expression
184 @item After an open-group, signified by
185 @samp{\(}
187 @item After the alternation operator @samp{\|}
189 @end enumerate
192 The character @samp{$} only represents the end of a string when it appears:
193 @enumerate
195 @item At the end of a regular expression
197 @item Before a close-group, signified by
198 @samp{\)}
199 @item Before the alternation operator @samp{\|}
201 @end enumerate
204 @samp{\*}, @samp{\+} and @samp{\?} are special at any point in a regular expression except:
205 @enumerate
207 @item At the beginning of a regular expression
209 @item After an open-group, signified by
210 @samp{\(}
211 @item After the alternation operator @samp{\|}
213 @end enumerate
216 Intervals are specified by @samp{\@{} and @samp{\@}}.  Invalid intervals such as @samp{a\@{1z} are not accepted.
218 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
221 @node emacs regular expression syntax
222 @subsection @samp{emacs} regular expression syntax
225 The character @samp{.} matches any single character except newline.
228 @table @samp
230 @item +
231 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
232 @item ?
233 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
234 @item \+
235 matches a @samp{+}
236 @item \?
237 matches a @samp{?}.
238 @end table
241 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are ignored.  Within square brackets, @samp{\} is taken literally.  Character classes are not supported, so for example you would need to use @samp{[0-9]} instead of @samp{[[:digit:]]}.
243 GNU extensions are supported:
244 @enumerate
246 @item @samp{\w} matches a character within a word
248 @item @samp{\W} matches a character which is not within a word
250 @item @samp{\<} matches the beginning of a word
252 @item @samp{\>} matches the end of a word
254 @item @samp{\b} matches a word boundary
256 @item @samp{\B} matches characters which are not a word boundary
258 @item @samp{\`} matches the beginning of the whole input
260 @item @samp{\'} matches the end of the whole input
262 @end enumerate
265 Grouping is performed with backslashes followed by parentheses @samp{\(}, @samp{\)}.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{\(}.
267 The alternation operator is @samp{\|}.
269 The character @samp{^} only represents the beginning of a string when it appears:
270 @enumerate
272 @item
273 At the beginning of a regular expression
275 @item After an open-group, signified by
276 @samp{\(}
278 @item After the alternation operator @samp{\|}
280 @end enumerate
283 The character @samp{$} only represents the end of a string when it appears:
284 @enumerate
286 @item At the end of a regular expression
288 @item Before a close-group, signified by
289 @samp{\)}
290 @item Before the alternation operator @samp{\|}
292 @end enumerate
295 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except:
296 @enumerate
298 @item At the beginning of a regular expression
300 @item After an open-group, signified by
301 @samp{\(}
302 @item After the alternation operator @samp{\|}
304 @end enumerate
309 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
312 @node gnu-awk regular expression syntax
313 @subsection @samp{gnu-awk} regular expression syntax
316 The character @samp{.} matches any single character.
319 @table @samp
321 @item +
322 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
323 @item ?
324 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
325 @item \+
326 matches a @samp{+}
327 @item \?
328 matches a @samp{?}.
329 @end table
332 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are invalid.  Within square brackets, @samp{\} can be used to quote the following character.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.
334 GNU extensions are supported:
335 @enumerate
337 @item @samp{\w} matches a character within a word
339 @item @samp{\W} matches a character which is not within a word
341 @item @samp{\<} matches the beginning of a word
343 @item @samp{\>} matches the end of a word
345 @item @samp{\b} matches a word boundary
347 @item @samp{\B} matches characters which are not a word boundary
349 @item @samp{\`} matches the beginning of the whole input
351 @item @samp{\'} matches the end of the whole input
353 @end enumerate
356 Grouping is performed with parentheses @samp{()}.  An unmatched @samp{)} matches just itself.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{(}.
358 The alternation operator is @samp{|}.
360 The characters @samp{^} and @samp{$} always represent the beginning and end of a string respectively, except within square brackets.  Within brackets, @samp{^} can be used to invert the membership of the character class being specified.
362 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except:
363 @enumerate
365 @item At the beginning of a regular expression
367 @item After an open-group, signified by
368 @samp{(}
369 @item After the alternation operator @samp{|}
371 @end enumerate
376 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
379 @node grep regular expression syntax
380 @subsection @samp{grep} regular expression syntax
383 The character @samp{.} matches any single character except newline.
386 @table @samp
388 @item \+
389 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
390 @item \?
391 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
392 @item + and ?
393 match themselves.
394 @end table
397 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are ignored.  Within square brackets, @samp{\} is taken literally.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.  Non-matching lists @samp{[^@dots{}]} do not ever match newline.
399 GNU extensions are supported:
400 @enumerate
402 @item @samp{\w} matches a character within a word
404 @item @samp{\W} matches a character which is not within a word
406 @item @samp{\<} matches the beginning of a word
408 @item @samp{\>} matches the end of a word
410 @item @samp{\b} matches a word boundary
412 @item @samp{\B} matches characters which are not a word boundary
414 @item @samp{\`} matches the beginning of the whole input
416 @item @samp{\'} matches the end of the whole input
418 @end enumerate
421 Grouping is performed with backslashes followed by parentheses @samp{\(}, @samp{\)}.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{\(}.
423 The alternation operator is @samp{\|}.
425 The character @samp{^} only represents the beginning of a string when it appears:
426 @enumerate
428 @item
429 At the beginning of a regular expression
431 @item After an open-group, signified by
432 @samp{\(}
434 @item After a newline
436 @item After the alternation operator @samp{\|}
438 @end enumerate
441 The character @samp{$} only represents the end of a string when it appears:
442 @enumerate
444 @item At the end of a regular expression
446 @item Before a close-group, signified by
447 @samp{\)}
448 @item Before a newline
450 @item Before the alternation operator @samp{\|}
452 @end enumerate
455 @samp{\*}, @samp{\+} and @samp{\?} are special at any point in a regular expression except:
456 @enumerate
458 @item At the beginning of a regular expression
460 @item After an open-group, signified by
461 @samp{\(}
462 @item After a newline
464 @item After the alternation operator @samp{\|}
466 @end enumerate
469 Intervals are specified by @samp{\@{} and @samp{\@}}.  Invalid intervals such as @samp{a\@{1z} are not accepted.
471 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
474 @node posix-awk regular expression syntax
475 @subsection @samp{posix-awk} regular expression syntax
478 The character @samp{.} matches any single character except the null character.
481 @table @samp
483 @item +
484 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
485 @item ?
486 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
487 @item \+
488 matches a @samp{+}
489 @item \?
490 matches a @samp{?}.
491 @end table
494 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are invalid.  Within square brackets, @samp{\} can be used to quote the following character.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.
496 GNU extensions are not supported and so @samp{\w}, @samp{\W}, @samp{\<}, @samp{\>}, @samp{\b}, @samp{\B}, @samp{\`}, and @samp{\'} match @samp{w}, @samp{W}, @samp{<}, @samp{>}, @samp{b}, @samp{B}, @samp{`}, and @samp{'} respectively.
498 Grouping is performed with parentheses @samp{()}.  An unmatched @samp{)} matches just itself.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{(}.
500 The alternation operator is @samp{|}.
502 The characters @samp{^} and @samp{$} always represent the beginning and end of a string respectively, except within square brackets.  Within brackets, @samp{^} can be used to invert the membership of the character class being specified.
504 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except the following places, where they are not allowed:
505 @enumerate
507 @item At the beginning of a regular expression
509 @item After an open-group, signified by
510 @samp{(}
511 @item After the alternation operator @samp{|}
513 @end enumerate
516 Intervals are specified by @samp{@{} and @samp{@}}.  Invalid intervals such as @samp{a@{1z} are not accepted.
518 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
521 @node posix-basic regular expression syntax
522 @subsection @samp{posix-basic} regular expression syntax
523 This is a synonym for ed.
524 @node posix-egrep regular expression syntax
525 @subsection @samp{posix-egrep} regular expression syntax
528 The character @samp{.} matches any single character except newline.
531 @table @samp
533 @item +
534 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
535 @item ?
536 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
537 @item \+
538 matches a @samp{+}
539 @item \?
540 matches a @samp{?}.
541 @end table
544 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are ignored.  Within square brackets, @samp{\} is taken literally.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.  Non-matching lists @samp{[^@dots{}]} do not ever match newline.
546 GNU extensions are supported:
547 @enumerate
549 @item @samp{\w} matches a character within a word
551 @item @samp{\W} matches a character which is not within a word
553 @item @samp{\<} matches the beginning of a word
555 @item @samp{\>} matches the end of a word
557 @item @samp{\b} matches a word boundary
559 @item @samp{\B} matches characters which are not a word boundary
561 @item @samp{\`} matches the beginning of the whole input
563 @item @samp{\'} matches the end of the whole input
565 @end enumerate
568 Grouping is performed with parentheses @samp{()}.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{(}.
570 The alternation operator is @samp{|}.
572 The characters @samp{^} and @samp{$} always represent the beginning and end of a string respectively, except within square brackets.  Within brackets, @samp{^} can be used to invert the membership of the character class being specified.
574 The characters @samp{*}, @samp{+} and @samp{?} are special anywhere in a regular expression.
576 Intervals are specified by @samp{@{} and @samp{@}}.  Invalid intervals are treated as literals, for example @samp{a@{1} is treated as @samp{a\@{1}
578 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
581 @node posix-extended regular expression syntax
582 @subsection @samp{posix-extended} regular expression syntax
585 The character @samp{.} matches any single character except the null character.
588 @table @samp
590 @item +
591 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.
592 @item ?
593 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.
594 @item \+
595 matches a @samp{+}
596 @item \?
597 matches a @samp{?}.
598 @end table
601 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are invalid.  Within square brackets, @samp{\} is taken literally.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.
603 GNU extensions are supported:
604 @enumerate
606 @item @samp{\w} matches a character within a word
608 @item @samp{\W} matches a character which is not within a word
610 @item @samp{\<} matches the beginning of a word
612 @item @samp{\>} matches the end of a word
614 @item @samp{\b} matches a word boundary
616 @item @samp{\B} matches characters which are not a word boundary
618 @item @samp{\`} matches the beginning of the whole input
620 @item @samp{\'} matches the end of the whole input
622 @end enumerate
625 Grouping is performed with parentheses @samp{()}.  An unmatched @samp{)} matches just itself.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{(}.
627 The alternation operator is @samp{|}.
629 The characters @samp{^} and @samp{$} always represent the beginning and end of a string respectively, except within square brackets.  Within brackets, @samp{^} can be used to invert the membership of the character class being specified.
631 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except the following places, where they are not allowed:
632 @enumerate
634 @item At the beginning of a regular expression
636 @item After an open-group, signified by
637 @samp{(}
638 @item After the alternation operator @samp{|}
640 @end enumerate
643 Intervals are specified by @samp{@{} and @samp{@}}.  Invalid intervals such as @samp{a@{1z} are not accepted.
645 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
648 @node posix-minimal-basic regular expression syntax
649 @subsection @samp{posix-minimal-basic} regular expression syntax
652 The character @samp{.} matches any single character except the null character.
656 Bracket expressions are used to match ranges of characters.  Bracket expressions where the range is backward, for example @samp{[z-a]}, are invalid.  Within square brackets, @samp{\} is taken literally.  Character classes are supported; for example @samp{[[:digit:]]} will match a single decimal digit.
658 GNU extensions are supported:
659 @enumerate
661 @item @samp{\w} matches a character within a word
663 @item @samp{\W} matches a character which is not within a word
665 @item @samp{\<} matches the beginning of a word
667 @item @samp{\>} matches the end of a word
669 @item @samp{\b} matches a word boundary
671 @item @samp{\B} matches characters which are not a word boundary
673 @item @samp{\`} matches the beginning of the whole input
675 @item @samp{\'} matches the end of the whole input
677 @end enumerate
680 Grouping is performed with backslashes followed by parentheses @samp{\(}, @samp{\)}.  A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number.  For example @samp{\2} matches the second group expression.  The order of group expressions is determined by the position of their opening parenthesis @samp{\(}.
684 The character @samp{^} only represents the beginning of a string when it appears:
685 @enumerate
687 @item
688 At the beginning of a regular expression
690 @item After an open-group, signified by
691 @samp{\(}
693 @end enumerate
696 The character @samp{$} only represents the end of a string when it appears:
697 @enumerate
699 @item At the end of a regular expression
701 @item Before a close-group, signified by
702 @samp{\)}
703 @end enumerate
708 Intervals are specified by @samp{\@{} and @samp{\@}}.  Invalid intervals such as @samp{a\@{1z} are not accepted.
710 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.
713 @node sed regular expression syntax
714 @subsection @samp{sed} regular expression syntax
715 This is a synonym for ed.