autoupdate
[gnulib.git] / doc / regexprops-generic.texi
1 @menu
2 * awk regular expression syntax::
3 * egrep regular expression syntax::
4 * ed regular expression syntax::
5 * emacs regular expression syntax::
6 * gnu-awk regular expression syntax::
7 * grep regular expression syntax::
8 * posix-awk regular expression syntax::
9 * posix-basic regular expression syntax::
10 * posix-egrep regular expression syntax::
11 * posix-extended regular expression syntax::
12 * posix-minimal-basic regular expression syntax::
13 * sed regular expression syntax::
14 @end menu
15
16 @node awk regular expression syntax
17 @subsection @samp{awk} regular expression syntax
18
19
20 The character @samp{.} matches any single character except the null character.  
21
22
23 @table @samp
24
25 @item +
26 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
27 @item ?
28 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
29 @item \+
30 matches a @samp{+}
31 @item \?
32 matches a @samp{?}.  
33 @end table
34
35
36 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:]]}.  
37
38 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.  
39
40 Grouping is performed with parentheses @samp{()}.  An unmatched @samp{)} matches just itself.  A backslash followed by a digit matches that digit.  
41
42 The alternation operator is @samp{|}.  
43
44 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.  
45
46 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except:
47 @enumerate
48
49 @item At the beginning of a regular expression
50
51 @item After an open-group, signified by 
52 @samp{(}
53 @item After the alternation operator @samp{|}
54
55 @end enumerate
56
57
58
59
60 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
61
62
63 @node egrep regular expression syntax
64 @subsection @samp{egrep} regular expression syntax
65
66
67 The character @samp{.} matches any single character except newline.  
68
69
70 @table @samp
71
72 @item +
73 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
74 @item ?
75 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
76 @item \+
77 matches a @samp{+}
78 @item \?
79 matches a @samp{?}.  
80 @end table
81
82
83 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.  
84
85 GNU extensions are supported:
86 @enumerate
87
88 @item @samp{\w} matches a character within a word
89
90 @item @samp{\W} matches a character which is not within a word
91
92 @item @samp{\<} matches the beginning of a word
93
94 @item @samp{\>} matches the end of a word
95
96 @item @samp{\b} matches a word boundary
97
98 @item @samp{\B} matches characters which are not a word boundary
99
100 @item @samp{\`} matches the beginning of the whole input
101
102 @item @samp{\'} matches the end of the whole input
103
104 @end enumerate
105
106
107 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{(}.  
108
109 The alternation operator is @samp{|}.  
110
111 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.  
112
113 The characters @samp{*}, @samp{+} and @samp{?} are special anywhere in a regular expression.  
114
115
116
117 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
118
119
120 @node ed regular expression syntax
121 @subsection @samp{ed} regular expression syntax
122
123
124 The character @samp{.} matches any single character except the null character.  
125
126
127 @table @samp
128
129 @item \+
130 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
131 @item \?
132 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
133 @item + and ? 
134 match themselves.  
135 @end table
136
137
138 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.  
139
140 GNU extensions are supported:
141 @enumerate
142
143 @item @samp{\w} matches a character within a word
144
145 @item @samp{\W} matches a character which is not within a word
146
147 @item @samp{\<} matches the beginning of a word
148
149 @item @samp{\>} matches the end of a word
150
151 @item @samp{\b} matches a word boundary
152
153 @item @samp{\B} matches characters which are not a word boundary
154
155 @item @samp{\`} matches the beginning of the whole input
156
157 @item @samp{\'} matches the end of the whole input
158
159 @end enumerate
160
161
162 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{\(}.  
163
164 The alternation operator is @samp{\|}. 
165
166 The character @samp{^} only represents the beginning of a string when it appears:
167 @enumerate
168
169 @item 
170 At the beginning of a regular expression
171
172 @item After an open-group, signified by 
173 @samp{\(}
174
175 @item After the alternation operator @samp{\|}
176
177 @end enumerate
178
179
180 The character @samp{$} only represents the end of a string when it appears:
181 @enumerate
182
183 @item At the end of a regular expression
184
185 @item Before an close-group, signified by 
186 @samp{\)}
187 @item Before the alternation operator @samp{\|}
188
189 @end enumerate
190
191
192 @samp{\*}, @samp{\+} and @samp{\?} are special at any point in a regular expression except:
193 @enumerate
194
195 @item At the beginning of a regular expression
196
197 @item After an open-group, signified by 
198 @samp{\(}
199 @item After the alternation operator @samp{\|}
200
201 @end enumerate
202
203
204 Intervals are specified by @samp{\@{} and @samp{\@}}.  Invalid intervals such as @samp{a\@{1z} are not accepted.  
205
206 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
207
208
209 @node emacs regular expression syntax
210 @subsection @samp{emacs} regular expression syntax
211
212
213 The character @samp{.} matches any single character except newline.  
214
215
216 @table @samp
217
218 @item +
219 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
220 @item ?
221 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
222 @item \+
223 matches a @samp{+}
224 @item \?
225 matches a @samp{?}.  
226 @end table
227
228
229 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:]]}.  
230
231 GNU extensions are supported:
232 @enumerate
233
234 @item @samp{\w} matches a character within a word
235
236 @item @samp{\W} matches a character which is not within a word
237
238 @item @samp{\<} matches the beginning of a word
239
240 @item @samp{\>} matches the end of a word
241
242 @item @samp{\b} matches a word boundary
243
244 @item @samp{\B} matches characters which are not a word boundary
245
246 @item @samp{\`} matches the beginning of the whole input
247
248 @item @samp{\'} matches the end of the whole input
249
250 @end enumerate
251
252
253 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{\(}.  
254
255 The alternation operator is @samp{\|}. 
256
257 The character @samp{^} only represents the beginning of a string when it appears:
258 @enumerate
259
260 @item 
261 At the beginning of a regular expression
262
263 @item After an open-group, signified by 
264 @samp{\(}
265
266 @item After the alternation operator @samp{\|}
267
268 @end enumerate
269
270
271 The character @samp{$} only represents the end of a string when it appears:
272 @enumerate
273
274 @item At the end of a regular expression
275
276 @item Before an close-group, signified by 
277 @samp{\)}
278 @item Before the alternation operator @samp{\|}
279
280 @end enumerate
281
282
283 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except:
284 @enumerate
285
286 @item At the beginning of a regular expression
287
288 @item After an open-group, signified by 
289 @samp{\(}
290 @item After the alternation operator @samp{\|}
291
292 @end enumerate
293
294
295
296
297 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
298
299
300 @node gnu-awk regular expression syntax
301 @subsection @samp{gnu-awk} regular expression syntax
302
303
304 The character @samp{.} matches any single character.  
305
306
307 @table @samp
308
309 @item +
310 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
311 @item ?
312 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
313 @item \+
314 matches a @samp{+}
315 @item \?
316 matches a @samp{?}.  
317 @end table
318
319
320 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.  
321
322 GNU extensions are supported:
323 @enumerate
324
325 @item @samp{\w} matches a character within a word
326
327 @item @samp{\W} matches a character which is not within a word
328
329 @item @samp{\<} matches the beginning of a word
330
331 @item @samp{\>} matches the end of a word
332
333 @item @samp{\b} matches a word boundary
334
335 @item @samp{\B} matches characters which are not a word boundary
336
337 @item @samp{\`} matches the beginning of the whole input
338
339 @item @samp{\'} matches the end of the whole input
340
341 @end enumerate
342
343
344 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{(}.  
345
346 The alternation operator is @samp{|}.  
347
348 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.  
349
350 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except:
351 @enumerate
352
353 @item At the beginning of a regular expression
354
355 @item After an open-group, signified by 
356 @samp{(}
357 @item After the alternation operator @samp{|}
358
359 @end enumerate
360
361
362
363
364 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
365
366
367 @node grep regular expression syntax
368 @subsection @samp{grep} regular expression syntax
369
370
371 The character @samp{.} matches any single character except newline.  
372
373
374 @table @samp
375
376 @item \+
377 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
378 @item \?
379 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
380 @item + and ? 
381 match themselves.  
382 @end table
383
384
385 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.  
386
387 GNU extensions are supported:
388 @enumerate
389
390 @item @samp{\w} matches a character within a word
391
392 @item @samp{\W} matches a character which is not within a word
393
394 @item @samp{\<} matches the beginning of a word
395
396 @item @samp{\>} matches the end of a word
397
398 @item @samp{\b} matches a word boundary
399
400 @item @samp{\B} matches characters which are not a word boundary
401
402 @item @samp{\`} matches the beginning of the whole input
403
404 @item @samp{\'} matches the end of the whole input
405
406 @end enumerate
407
408
409 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{\(}.  
410
411 The alternation operator is @samp{\|}. 
412
413 The character @samp{^} only represents the beginning of a string when it appears:
414 @enumerate
415
416 @item 
417 At the beginning of a regular expression
418
419 @item After an open-group, signified by 
420 @samp{\(}
421
422 @item After a newline
423
424 @item After the alternation operator @samp{\|}
425
426 @end enumerate
427
428
429 The character @samp{$} only represents the end of a string when it appears:
430 @enumerate
431
432 @item At the end of a regular expression
433
434 @item Before an close-group, signified by 
435 @samp{\)}
436 @item Before a newline
437
438 @item Before the alternation operator @samp{\|}
439
440 @end enumerate
441
442
443 @samp{\*}, @samp{\+} and @samp{\?} are special at any point in a regular expression except:
444 @enumerate
445
446 @item At the beginning of a regular expression
447
448 @item After an open-group, signified by 
449 @samp{\(}
450 @item After a newline
451
452 @item After the alternation operator @samp{\|}
453
454 @end enumerate
455
456
457 Intervals are specified by @samp{\@{} and @samp{\@}}.  Invalid intervals such as @samp{a\@{1z} are not accepted.  
458
459 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
460
461
462 @node posix-awk regular expression syntax
463 @subsection @samp{posix-awk} regular expression syntax
464
465
466 The character @samp{.} matches any single character except the null character.  
467
468
469 @table @samp
470
471 @item +
472 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
473 @item ?
474 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
475 @item \+
476 matches a @samp{+}
477 @item \?
478 matches a @samp{?}.  
479 @end table
480
481
482 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.  
483
484 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.  
485
486 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{(}.  
487
488 The alternation operator is @samp{|}.  
489
490 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.  
491
492 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except the following places, where they are illegal:
493 @enumerate
494
495 @item At the beginning of a regular expression
496
497 @item After an open-group, signified by 
498 @samp{(}
499 @item After the alternation operator @samp{|}
500
501 @end enumerate
502
503
504 Intervals are specified by @samp{@{} and @samp{@}}.  Invalid intervals such as @samp{a@{1z} are not accepted.  
505
506 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
507
508
509 @node posix-basic regular expression syntax
510 @subsection @samp{posix-basic} regular expression syntax
511 This is a synonym for ed.
512 @node posix-egrep regular expression syntax
513 @subsection @samp{posix-egrep} regular expression syntax
514
515
516 The character @samp{.} matches any single character except newline.  
517
518
519 @table @samp
520
521 @item +
522 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
523 @item ?
524 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
525 @item \+
526 matches a @samp{+}
527 @item \?
528 matches a @samp{?}.  
529 @end table
530
531
532 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.  
533
534 GNU extensions are supported:
535 @enumerate
536
537 @item @samp{\w} matches a character within a word
538
539 @item @samp{\W} matches a character which is not within a word
540
541 @item @samp{\<} matches the beginning of a word
542
543 @item @samp{\>} matches the end of a word
544
545 @item @samp{\b} matches a word boundary
546
547 @item @samp{\B} matches characters which are not a word boundary
548
549 @item @samp{\`} matches the beginning of the whole input
550
551 @item @samp{\'} matches the end of the whole input
552
553 @end enumerate
554
555
556 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{(}.  
557
558 The alternation operator is @samp{|}.  
559
560 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.  
561
562 The characters @samp{*}, @samp{+} and @samp{?} are special anywhere in a regular expression.  
563
564 Intervals are specified by @samp{@{} and @samp{@}}.  Invalid intervals are treated as literals, for example @samp{a@{1} is treated as @samp{a\@{1}
565
566 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
567
568
569 @node posix-extended regular expression syntax
570 @subsection @samp{posix-extended} regular expression syntax
571
572
573 The character @samp{.} matches any single character except the null character.  
574
575
576 @table @samp
577
578 @item +
579 indicates that the regular expression should match one or more occurrences of the previous atom or regexp.  
580 @item ?
581 indicates that the regular expression should match zero or one occurrence of the previous atom or regexp.  
582 @item \+
583 matches a @samp{+}
584 @item \?
585 matches a @samp{?}.  
586 @end table
587
588
589 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.  
590
591 GNU extensions are supported:
592 @enumerate
593
594 @item @samp{\w} matches a character within a word
595
596 @item @samp{\W} matches a character which is not within a word
597
598 @item @samp{\<} matches the beginning of a word
599
600 @item @samp{\>} matches the end of a word
601
602 @item @samp{\b} matches a word boundary
603
604 @item @samp{\B} matches characters which are not a word boundary
605
606 @item @samp{\`} matches the beginning of the whole input
607
608 @item @samp{\'} matches the end of the whole input
609
610 @end enumerate
611
612
613 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{(}.  
614
615 The alternation operator is @samp{|}.  
616
617 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.  
618
619 @samp{*}, @samp{+} and @samp{?} are special at any point in a regular expression except the following places, where they are illegal:
620 @enumerate
621
622 @item At the beginning of a regular expression
623
624 @item After an open-group, signified by 
625 @samp{(}
626 @item After the alternation operator @samp{|}
627
628 @end enumerate
629
630
631 Intervals are specified by @samp{@{} and @samp{@}}.  Invalid intervals such as @samp{a@{1z} are not accepted.  
632
633 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
634
635
636 @node posix-minimal-basic regular expression syntax
637 @subsection @samp{posix-minimal-basic} regular expression syntax
638
639
640 The character @samp{.} matches any single character except the null character.  
641
642
643
644 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.  
645
646 GNU extensions are supported:
647 @enumerate
648
649 @item @samp{\w} matches a character within a word
650
651 @item @samp{\W} matches a character which is not within a word
652
653 @item @samp{\<} matches the beginning of a word
654
655 @item @samp{\>} matches the end of a word
656
657 @item @samp{\b} matches a word boundary
658
659 @item @samp{\B} matches characters which are not a word boundary
660
661 @item @samp{\`} matches the beginning of the whole input
662
663 @item @samp{\'} matches the end of the whole input
664
665 @end enumerate
666
667
668 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{\(}.  
669
670
671
672 The character @samp{^} only represents the beginning of a string when it appears:
673 @enumerate
674
675 @item 
676 At the beginning of a regular expression
677
678 @item After an open-group, signified by 
679 @samp{\(}
680
681 @end enumerate
682
683
684 The character @samp{$} only represents the end of a string when it appears:
685 @enumerate
686
687 @item At the end of a regular expression
688
689 @item Before an close-group, signified by 
690 @samp{\)}
691 @end enumerate
692
693
694
695
696 Intervals are specified by @samp{\@{} and @samp{\@}}.  Invalid intervals such as @samp{a\@{1z} are not accepted.  
697
698 The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.  
699
700
701 @node sed regular expression syntax
702 @subsection @samp{sed} regular expression syntax
703 This is a synonym for ed.