]> git.saurik.com Git - apple/libc.git/blob - regex/FreeBSD/re_format.7
Libc-1439.100.3.tar.gz
[apple/libc.git] / regex / FreeBSD / re_format.7
1 .\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
2 .\" Copyright (c) 1992, 1993, 1994
3 .\" The Regents of the University of California. All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Henry Spencer.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\" must display the following acknowledgement:
18 .\" This product includes software developed by the University of
19 .\" California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\" may be used to endorse or promote products derived from this software
22 .\" without specific prior written permission.
23 .\"
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" SUCH DAMAGE.
35 .\"
36 .\" @(#)re_format.7 8.3 (Berkeley) 3/20/94
37 .\" $FreeBSD: src/lib/libc/regex/re_format.7,v 1.12 2008/09/05 17:41:20 keramida Exp $
38 .\"
39 .Dd Sept 29, 2011
40 .Dt RE_FORMAT 7
41 .Os
42 .Sh NAME
43 .Nm re_format
44 .Nd POSIX 1003.2 regular expressions
45 .Sh DESCRIPTION
46 Regular expressions
47 .Pq Dq RE Ns s ,
48 as defined in
49 .St -p1003.2 ,
50 come in two forms:
51 modern REs (roughly those of
52 .Xr egrep 1 ;
53 1003.2 calls these
54 .Dq extended
55 REs)
56 and obsolete REs (roughly those of
57 .Xr ed 1 ;
58 1003.2
59 .Dq basic
60 REs).
61 Obsolete REs mostly exist for backward compatibility in some old programs;
62 they will be discussed at the end.
63 .St -p1003.2
64 leaves some aspects of RE syntax and semantics open;
65 `\(dd' marks decisions on these aspects that
66 may not be fully portable to other
67 .St -p1003.2
68 implementations.
69 .Pp
70 A (modern) RE is one\(dd or more non-empty\(dd
71 .Em branches ,
72 separated by
73 .Ql \&| .
74 It matches anything that matches one of the branches.
75 .Pp
76 A branch is one\(dd or more
77 .Em pieces ,
78 concatenated.
79 It matches a match for the first, followed by a match for the second, etc.
80 .Pp
81 A piece is an
82 .Em atom
83 possibly followed
84 by a single\(dd
85 .Ql \&* ,
86 .Ql \&+ ,
87 .Ql \&? ,
88 or
89 .Em bound .
90 An atom followed by
91 .Ql \&*
92 matches a sequence of 0 or more matches of the atom.
93 An atom followed by
94 .Ql \&+
95 matches a sequence of 1 or more matches of the atom.
96 An atom followed by
97 .Ql ?\&
98 matches a sequence of 0 or 1 matches of the atom.
99 .Pp
100 A
101 .Em bound
102 is
103 .Ql \&{
104 followed by an unsigned decimal integer,
105 possibly followed by
106 .Ql \&,
107 possibly followed by another unsigned decimal integer,
108 always followed by
109 .Ql \&} .
110 The integers must lie between 0 and
111 .Dv RE_DUP_MAX
112 (255\(dd) inclusive,
113 and if there are two of them, the first may not exceed the second.
114 An atom followed by a bound containing one integer
115 .Em i
116 and no comma matches
117 a sequence of exactly
118 .Em i
119 matches of the atom.
120 An atom followed by a bound
121 containing one integer
122 .Em i
123 and a comma matches
124 a sequence of
125 .Em i
126 or more matches of the atom.
127 An atom followed by a bound
128 containing two integers
129 .Em i
130 and
131 .Em j
132 matches
133 a sequence of
134 .Em i
135 through
136 .Em j
137 (inclusive) matches of the atom.
138 .Pp
139 An atom is a regular expression enclosed in
140 .Ql ()
141 (matching a match for the
142 regular expression),
143 an empty set of
144 .Ql ()
145 (matching the null string)\(dd,
146 a
147 .Em bracket expression
148 (see below),
149 .Ql .\&
150 (matching any single character),
151 .Ql \&^
152 (matching the null string at the beginning of a line),
153 .Ql \&$
154 (matching the null string at the end of a line), a
155 .Ql \e
156 followed by one of the characters
157 .Ql ^.[$()|*+?{\e
158 (matching that character taken as an ordinary character),
159 a
160 .Ql \e
161 followed by any other character\(dd
162 (matching that character taken as an ordinary character,
163 as if the
164 .Ql \e
165 had not been present\(dd),
166 or a single character with no other significance (matching that character).
167 A
168 .Ql \&{
169 followed by a character other than a digit is an ordinary
170 character, not the beginning of a bound\(dd.
171 It is illegal to end an RE with
172 .Ql \e .
173 .Pp
174 A
175 .Em bracket expression
176 is a list of characters enclosed in
177 .Ql [] .
178 It normally matches any single character from the list (but see below).
179 If the list begins with
180 .Ql \&^ ,
181 it matches any single character
182 (but see below)
183 .Em not
184 from the rest of the list.
185 If two characters in the list are separated by
186 .Ql \&- ,
187 this is shorthand
188 for the full
189 .Em range
190 of characters between those two (inclusive) in the
191 collating sequence,
192 .No e.g. Ql [0-9]
193 in ASCII matches any decimal digit.
194 It is illegal\(dd for two ranges to share an
195 endpoint,
196 .No e.g. Ql a-c-e .
197 Ranges are very collating-sequence-dependent,
198 and portable programs should avoid relying on them.
199 .Pp
200 To include a literal
201 .Ql \&]
202 in the list, make it the first character
203 (following a possible
204 .Ql \&^ ) .
205 To include a literal
206 .Ql \&- ,
207 make it the first or last character,
208 or the second endpoint of a range.
209 To use a literal
210 .Ql \&-
211 as the first endpoint of a range,
212 enclose it in
213 .Ql [.\&
214 and
215 .Ql .]\&
216 to make it a collating element (see below).
217 With the exception of these and some combinations using
218 .Ql \&[
219 (see next paragraphs), all other special characters, including
220 .Ql \e ,
221 lose their special significance within a bracket expression.
222 .Pp
223 Within a bracket expression, a collating element (a character,
224 a multi-character sequence that collates as if it were a single character,
225 or a collating-sequence name for either)
226 enclosed in
227 .Ql [.\&
228 and
229 .Ql .]\&
230 stands for the
231 sequence of characters of that collating element.
232 The sequence is a single element of the bracket expression's list.
233 A bracket expression containing a multi-character collating element
234 can thus match more than one character,
235 e.g.\& if the collating sequence includes a
236 .Ql ch
237 collating element,
238 then the RE
239 .Ql [[.ch.]]*c
240 matches the first five characters
241 of
242 .Ql chchcc .
243 .Pp
244 Within a bracket expression, a collating element enclosed in
245 .Ql [=
246 and
247 .Ql =]
248 is an equivalence class, standing for the sequences of characters
249 of all collating elements equivalent to that one, including itself.
250 (If there are no other equivalent collating elements,
251 the treatment is as if the enclosing delimiters were
252 .Ql [.\&
253 and
254 .Ql .] . )
255 For example, if
256 .Ql x
257 and
258 .Ql y
259 are the members of an equivalence class,
260 then
261 .Ql [[=x=]] ,
262 .Ql [[=y=]] ,
263 and
264 .Ql [xy]
265 are all synonymous.
266 An equivalence class may not\(dd be an endpoint
267 of a range.
268 .Pp
269 Within a bracket expression, the name of a
270 .Em character class
271 enclosed in
272 .Ql [:
273 and
274 .Ql :]
275 stands for the list of all characters belonging to that
276 class.
277 Standard character class names are:
278 .Pp
279 .Bl -column "alnum" "digit" "xdigit" -offset indent
280 .It Em "alnum digit punct"
281 .It Em "alpha graph space"
282 .It Em "blank lower upper"
283 .It Em "cntrl print xdigit"
284 .El
285 .Pp
286 These stand for the character classes defined in
287 .Xr ctype 3 .
288 A locale may provide others.
289 A character class may not be used as an endpoint of a range.
290 .Pp
291 A bracketed expression like
292 .Ql [[:class:]]
293 can be used to match a single character that belongs to a character
294 class.
295 The reverse, matching any character that does not belong to a specific
296 class, the negation operator of bracket expressions may be used:
297 .Ql [^[:class:]] .
298 .Pp
299 There are two special cases\(dd of bracket expressions:
300 the bracket expressions
301 .Ql [[:<:]]
302 and
303 .Ql [[:>:]]
304 match the null string at the beginning and end of a word respectively.
305 A word is defined as a sequence of word characters
306 which is neither preceded nor followed by
307 word characters.
308 A word character is an
309 .Em alnum
310 character (as defined by
311 .Xr ctype 3 )
312 or an underscore.
313 This is an extension,
314 compatible with but not specified by
315 .St -p1003.2 ,
316 and should be used with
317 caution in software intended to be portable to other systems.
318 .Pp
319 In the event that an RE could match more than one substring of a given
320 string,
321 the RE matches the one starting earliest in the string.
322 If the RE could match more than one substring starting at that point,
323 it matches the longest.
324 Subexpressions also match the longest possible substrings, subject to
325 the constraint that the whole match be as long as possible,
326 with subexpressions starting earlier in the RE taking priority over
327 ones starting later.
328 Note that higher-level subexpressions thus take priority over
329 their lower-level component subexpressions.
330 .Pp
331 Match lengths are measured in characters, not collating elements.
332 A null string is considered longer than no match at all.
333 For example,
334 .Ql bb*
335 matches the three middle characters of
336 .Ql abbbc ,
337 .Ql (wee|week)(knights|nights)
338 matches all ten characters of
339 .Ql weeknights ,
340 when
341 .Ql (.*).*\&
342 is matched against
343 .Ql abc
344 the parenthesized subexpression
345 matches all three characters, and
346 when
347 .Ql (a*)*
348 is matched against
349 .Ql bc
350 both the whole RE and the parenthesized
351 subexpression match the null string.
352 .Pp
353 If case-independent matching is specified,
354 the effect is much as if all case distinctions had vanished from the
355 alphabet.
356 When an alphabetic that exists in multiple cases appears as an
357 ordinary character outside a bracket expression, it is effectively
358 transformed into a bracket expression containing both cases,
359 .No e.g. Ql x
360 becomes
361 .Ql [xX] .
362 When it appears inside a bracket expression, all case counterparts
363 of it are added to the bracket expression, so that (e.g.)
364 .Ql [x]
365 becomes
366 .Ql [xX]
367 and
368 .Ql [^x]
369 becomes
370 .Ql [^xX] .
371 .Pp
372 No particular limit is imposed on the length of REs\(dd.
373 Programs intended to be portable should not employ REs longer
374 than 256 bytes,
375 as an implementation can refuse to accept such REs and remain
376 POSIX-compliant.
377 .Pp
378 Obsolete
379 .Pq Dq basic
380 regular expressions differ in several respects.
381 .Ql \&|
382 is an ordinary character and there is no equivalent
383 for its functionality.
384 .Ql \&+
385 and
386 .Ql ?\&
387 are ordinary characters, and their functionality
388 can be expressed using bounds
389 .No ( Ql {1,}
390 or
391 .Ql {0,1}
392 respectively).
393 Also note that
394 .Ql x+
395 in modern REs is equivalent to
396 .Ql xx* .
397 The delimiters for bounds are
398 .Ql \e{
399 and
400 .Ql \e} ,
401 with
402 .Ql \&{
403 and
404 .Ql \&}
405 by themselves ordinary characters.
406 The parentheses for nested subexpressions are
407 .Ql \e(
408 and
409 .Ql \e) ,
410 with
411 .Ql \&(
412 and
413 .Ql \&)
414 by themselves ordinary characters.
415 .Ql \&^
416 is an ordinary character except at the beginning of the
417 RE or\(dd the beginning of a parenthesized subexpression,
418 .Ql \&$
419 is an ordinary character except at the end of the
420 RE or\(dd the end of a parenthesized subexpression,
421 and
422 .Ql \&*
423 is an ordinary character if it appears at the beginning of the
424 RE or the beginning of a parenthesized subexpression
425 (after a possible leading
426 .Ql \&^ ) .
427 Finally, there is one new type of atom, a
428 .Em back reference :
429 .Ql \e
430 followed by a non-zero decimal digit
431 .Em d
432 matches the same sequence of characters
433 matched by the
434 .Em d Ns th
435 parenthesized subexpression
436 (numbering subexpressions by the positions of their opening parentheses,
437 left to right),
438 so that (e.g.)
439 .Ql \e([bc]\e)\e1
440 matches
441 .Ql bb
442 or
443 .Ql cc
444 but not
445 .Ql bc .
446 .Sh ENHANCED FEATURES
447 When the
448 .Dv REG_ENHANCED
449 flag is passed to one of the
450 .Fn regcomp
451 variants, additional features are activated.
452 Like the enhanced
453 .Nm regex
454 implementations in scripting languages such as
455 .Xr perl 1
456 and
457 .Xr python 1 ,
458 these additional features may conflict with the
459 .St -p1003.2
460 standards in some ways.
461 Use this with care in situations which require portability
462 (including to past versions of the Mac OS X using the previous
463 .Nm regex
464 implementation).
465 .Pp
466 For enhanced basic REs,
467 .Ql \&+ ,
468 .Ql \&?
469 and
470 .Ql \&|
471 remain regular characters, but
472 .Ql \e+ ,
473 .Ql \e?
474 and
475 .Ql \e|
476 have the same special meaning as the unescaped characters do for
477 extended REs, i.e., one or more matches, zero or one matches and alteration,
478 respectively.
479 For enhanced extended REs,
480 back references are available.
481 Additional enhanced features are listed below.
482 .Pp
483 Within a bracket expression, most characters lose their magic.
484 This also applies to the additional enhanced features, which don't operate
485 inside a bracket expression.
486 .Ss Assertions (available for both enhanced basic and enhanced extended REs)
487 In addition to
488 .Ql \&^
489 and
490 .Ql \&$
491 (the assertions that match the null string at the beginning and end of line,
492 respectively), the following assertions become available:
493 .Bl -tag -width ".Sy \eB" -offset indent
494 .It Sy \e<
495 Matches the null string at the beginning of a word.
496 This is equivalent to
497 .Ql [[:<:]] .
498 .It Sy \e>
499 Matches the null string at the end of a word.
500 This is equivalent to
501 .Ql [[:>:]] .
502 .It Sy \eb
503 Matches the null string at a word boundary (either the beginning or end of
504 a word).
505 .It Sy \eB
506 Matches the null string where there is no word boundary.
507 This is the opposite of
508 .Ql \eb .
509 .El
510 .Ss Shortcuts (available for both enhanced basic and enhanced extended REs)
511 The following shortcuts can be used to replace more complicated
512 bracket expressions.
513 .Bl -tag -width ".Sy \eD" -offset indent
514 .It Sy \ed
515 Matches a digit character.
516 This is equivalent to
517 .Ql [[:digit:]] .
518 .It Sy \eD
519 Matches a non-digit character.
520 This is equivalent to
521 .Ql [^[:digit:]] .
522 .It Sy \es
523 Matches a space character.
524 This is equivalent to
525 .Ql [[:space:]] .
526 .It Sy \eS
527 Matches a non-space character.
528 This is equivalent to
529 .Ql [^[:space:]] .
530 .It Sy \ew
531 Matches a word character.
532 This is equivalent to
533 .Ql [[:alnum:]_] .
534 .It Sy \eW
535 Matches a non-word character.
536 This is equivalent to
537 .Ql [^[:alnum:]_] .
538 .El
539 .Ss Literal Sequences (available for both enhanced basic and enhanced extended REs)
540 .Pp
541 Literals are normally just ordinary characters that are matched directly.
542 Under enhanced mode, certain character sequences are
543 converted to specific literals.
544 .Bl -tag -width ".Sy \ea" -offset indent
545 .It Sy \ea
546 The
547 .Dq bell
548 character (ASCII code 7).
549 .It Sy \ee
550 The
551 .Dq escape
552 character (ASCII code 27).
553 .It Sy \ef
554 The
555 .Dq form-feed
556 character (ASCII code 12).
557 .It Sy \en
558 The
559 .Dq new-line/line-feed
560 character (ASCII code 10).
561 .It Sy \er
562 The
563 .Dq carriage-return
564 character (ASCII code 13).
565 .It Sy \et
566 The
567 .Dq horizontal-tab
568 character (ASCII code 9).
569 .El
570 .Pp
571 Literals can also be specified directly, using their wide character values.
572 Note that when matching a multibyte character string, the string's bytes
573 are converted to wide character before comparing.
574 This means that a single literal wide character value may match more than
575 one string byte, depending on the locale's wide character encoding.
576 .Bl -tag -width ".Sy \ex{ Ns Em x.. Ns Sy \&}" -offset indent
577 .It Sy \ex Ns Em x..
578 An arbitray eight-bit value.
579 The
580 .Em x..
581 sequence represents zero, one or two hexadecimal digits.
582 (Note: if
583 .Em x..
584 is less than two hexadecimal digits, and the character following this sequence
585 happens to be a hexadecimal digit, use the (following) brace form to avoid
586 confusion.)
587 .It Sy \ex{ Ns Em x.. Ns Sy \&}
588 An arbitrary, up to 32-bit value.
589 The
590 .Em x..
591 sequence is an arbitrary sequence of hexadecimal digits that is long enough
592 to represent the necessary value.
593 .El
594 .Ss Inline Literal Mode (available for both enhanced basic and enhanced extended REs)
595 A
596 .Ql \eQ
597 sequence causes literal
598 .Pq Dq quote
599 mode to be entered,
600 while
601 .Ql \eE
602 ends literal mode, and returns to normal regular expression processing.
603 This is similar to specifying the
604 .Dv REG_NOSPEC
605 (or
606 .Dv REG_LITERAL )
607 option to
608 .Fn regcomp ,
609 except that rather than applying to the whole RE string, it only applies to
610 the part between the
611 .Ql \eQ
612 and
613 .Ql \eE .
614 Note that it is not possible to have a
615 .Ql \eE
616 in the middle of an inline literal range, as that would terminate literal mode
617 prematurely.
618 .Ss Minimal Repetitions (available for enhanced extended REs only)
619 By default, the repetition operators,
620 .Ql \&* ,
621 .Em bound ,
622 .Ql \&?
623 and
624 .Ql \&+
625 are
626 .Em greedy ;
627 they try to match as many times as possible.
628 In enhanced mode, appending a
629 .Ql \&?
630 to a repetition operator makes it minimal (or
631 .Em ungreedy ) ;
632 it tries to match the fewest number of times (including zero times, as
633 appropriate).
634 .Pp
635 For example, against the string
636 .Ql aaa ,
637 the RE
638 .Ql a*
639 would match the entire string,
640 while
641 .Ql a*?
642 would match the null string at the beginning of the line
643 (matches zero times).
644 Likewise, against the string
645 .Ql ababab ,
646 the RE
647 .Ql .*b ,
648 would also match the entire string,
649 while
650 .Ql .*?b
651 would only match the first two characters.
652 .Pp
653 The
654 .Fn regcomp
655 flag
656 .Dv REG_UNGREEDY
657 will make the regular
658 .Pq greedy
659 repetition operators ungreedy by default.
660 Appending
661 .Ql \&?
662 makes them greedy again.
663 .Pp
664 Note that minimal repetitions are not specified by an official
665 standard, so there may be differences between different implementations.
666 In the current implementation, minimal repetitions have a high precedence,
667 and can cause other standards requirements to be violated.
668 For instance, on the string
669 .Ql aaaaa ,
670 the RE
671 .Ql (aaa??)*
672 will only match the first four characters, violating the rules that the longest
673 possible match is made and the longest subexpressions are matched.
674 Using
675 .Ql (aaa??)*$
676 forces the entire string to be matched.
677 .Ss Non-capturing Parenthesized Subexpressions (available for enhanced extended REs only)
678 Normally, the match offsets to parenthesized subexpressions are
679 recorded in the
680 .Fa pmatch
681 array (that is, when
682 .Dv REG_NOSUB
683 is not specified, and
684 .Fa nmatch
685 is large enough to encompass the parenthesized subexpression in question).
686 In enhanced mode, if the first two characters following the left parenthesis
687 are
688 .Ql ?: ,
689 grouping of the remaining contents is done, but the corresponding offsets are
690 not recorded in the
691 .Fa pmatch
692 array.
693 For example, against the string
694 .Ql fubar ,
695 the RE
696 .Ql (fu)(bar)
697 would have two subexpression matches in
698 .Fa pmatch ;
699 the first for
700 .Ql fu
701 and the second for
702 .Ql bar .
703 But with the RE
704 .Ql (?:fu)(bar) ,
705 there would only be one subexpression match, that of
706 .Ql bar .
707 Furthermore,
708 against the string
709 .Ql fufubar ,
710 the RE
711 .Ql (?fu)*(bar)
712 would again match the entire string, but only
713 .Ql bar
714 would be recorded in
715 .Fa pmatch .
716 .Ss Inline Options (available for enhanced extended REs only)
717 Like the inline literal mode mentioned above, other options can be switched
718 on and off for part of a RE.
719 .Ql (? Ns Em o.. Ns \&)
720 will turn on the options specified in
721 .Em o..
722 (one or more options characters; see below), while
723 .Ql (?- Ns Em o.. Ns \&)
724 will turn off the specified options, and
725 .Ql (? Ns Em o1.. Ns \&- Ns Em o2.. Ns \&)
726 will turn on the first set of options, and turn off the second set.
727 .Pp
728 The available options are:
729 .Bl -tag -width ".Sy \&U" -offset indent
730 .It Sy \&i
731 Turning on this option will ignore case during matching, while turning off
732 will restore case-sensitive matching.
733 If
734 .Dv REG_ICASE
735 was specified to
736 .Fn regcomp ,
737 this option can be use to turn that off.
738 .It Sy \&n
739 Turn on or off special handling of the newline character.
740 If
741 .Dv REG_NEWLINE
742 was specified to
743 .Fn regcomp ,
744 this option can be use to turn that off.
745 .It Sy \&U
746 Turning on this option will make ungreedy repetitions the default, while
747 turning off will make greedy repetitions the default.
748 If
749 .Dv REG_UNGREEDY
750 was specified to
751 .Fn regcomp ,
752 this option can be use to turn that off.
753 .El
754 .Pp
755 The scope of the option change begins immediately following the right
756 parenthesis,
757 but up to the end of the enclosing subexpression (if any).
758 Thus, for example, given the RE
759 .Ql (fu(?i)bar)baz ,
760 the
761 .Ql fu
762 portion matches case sensitively,
763 .Ql bar
764 matches case insensitively, and
765 .Ql baz
766 matches case sensitively again (since is it outside the scope of the
767 subexpression in which the inline option was specified).
768 .Pp
769 The inline options syntax can be combined with the non-capturing parenthesized
770 subexpression to limit the option scope to just that of the subexpression.
771 Then, for example,
772 .Ql fu(?i:bar)baz
773 is similar to the previous example, except for the parenthesize subexpression
774 around
775 .Ql fu(?i)bar
776 in the previous example.
777 .Ss Inline Comments (available for enhanced extended REs only)
778 The syntax
779 .Ql (?# Ns Em comment Ns \&)
780 can be used to embed comments within a RE.
781 Note that
782 .Em comment
783 can not contain a right parenthesis.
784 Also note that while syntactically, option characters can be added before
785 the
786 .Ql \&#
787 character, they will be ignored.
788 .Sh SEE ALSO
789 .Xr regex 3
790 .Rs
791 .%T Regular Expression Notation
792 .%R IEEE Std
793 .%N 1003.2
794 .%P section 2.8
795 .Re
796 .Sh BUGS
797 Having two kinds of REs is a botch.
798 .Pp
799 The current
800 .St -p1003.2
801 spec says that
802 .Ql \&)
803 is an ordinary character in
804 the absence of an unmatched
805 .Ql \&( ;
806 this was an unintentional result of a wording error,
807 and change is likely.
808 Avoid relying on it.
809 .Pp
810 Back references are a dreadful botch,
811 posing major problems for efficient implementations.
812 They are also somewhat vaguely defined
813 (does
814 .Ql a\e(\e(b\e)*\e2\e)*d
815 match
816 .Ql abbbd ? ) .
817 Avoid using them.
818 .Pp
819 .St -p1003.2
820 specification of case-independent matching is vague.
821 The
822 .Dq one case implies all cases
823 definition given above
824 is current consensus among implementors as to the right interpretation.
825 .Pp
826 The bracket syntax for word boundaries is incredibly ugly.