1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>POSIX Extended Regular Expression Syntax</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Boost.Regex 5.1.2">
<link rel="up" href="../syntax.html" title="Regular Expression Syntax">
<link rel="prev" href="perl_syntax.html" title="Perl Regular Expression Syntax">
<link rel="next" href="basic_syntax.html" title="POSIX Basic Regular Expression Syntax">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="perl_syntax.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../syntax.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="basic_syntax.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_regex.syntax.basic_extended"></a><a class="link" href="basic_extended.html" title="POSIX Extended Regular Expression Syntax">POSIX Extended Regular
Expression Syntax</a>
</h3></div></div></div>
<h4>
<a name="boost_regex.syntax.basic_extended.h0"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.synopsis"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.synopsis">Synopsis</a>
</h4>
<p>
The POSIX-Extended regular expression syntax is supported by the POSIX C
regular expression API's, and variations are used by the utilities <code class="computeroutput"><span class="identifier">egrep</span></code> and <code class="computeroutput"><span class="identifier">awk</span></code>.
You can construct POSIX extended regular expressions in Boost.Regex by passing
the flag <code class="computeroutput"><span class="identifier">extended</span></code> to the
regex constructor, for example:
</p>
<pre class="programlisting"><span class="comment">// e1 is a case sensitive POSIX-Extended expression:</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span> <span class="identifier">e1</span><span class="special">(</span><span class="identifier">my_expression</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span><span class="special">::</span><span class="identifier">extended</span><span class="special">);</span>
<span class="comment">// e2 a case insensitive POSIX-Extended expression:</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span> <span class="identifier">e2</span><span class="special">(</span><span class="identifier">my_expression</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span><span class="special">::</span><span class="identifier">extended</span><span class="special">|</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span><span class="special">::</span><span class="identifier">icase</span><span class="special">);</span>
</pre>
<a name="boost_regex.posix_extended_syntax"></a><h4>
<a name="boost_regex.syntax.basic_extended.h1"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.posix_extended_syntax"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.posix_extended_syntax">POSIX Extended
Syntax</a>
</h4>
<p>
In POSIX-Extended regular expressions, all characters match themselves except
for the following special characters:
</p>
<pre class="programlisting">.[{}()\*+?|^$</pre>
<h5>
<a name="boost_regex.syntax.basic_extended.h2"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.wildcard"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.wildcard">Wildcard:</a>
</h5>
<p>
The single character '.' when used outside of a character set will match
any single character except:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The NULL character when the flag <code class="computeroutput"><span class="identifier">match_no_dot_null</span></code>
is passed to the matching algorithms.
</li>
<li class="listitem">
The newline character when the flag <code class="computeroutput"><span class="identifier">match_not_dot_newline</span></code>
is passed to the matching algorithms.
</li>
</ul></div>
<h5>
<a name="boost_regex.syntax.basic_extended.h3"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.anchors"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.anchors">Anchors:</a>
</h5>
<p>
A '^' character shall match the start of a line when used as the first character
of an expression, or the first character of a sub-expression.
</p>
<p>
A '$' character shall match the end of a line when used as the last character
of an expression, or the last character of a sub-expression.
</p>
<h5>
<a name="boost_regex.syntax.basic_extended.h4"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.marked_sub_expressions"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.marked_sub_expressions">Marked
sub-expressions:</a>
</h5>
<p>
A section beginning <code class="computeroutput"><span class="special">(</span></code> and ending
<code class="computeroutput"><span class="special">)</span></code> acts as a marked sub-expression.
Whatever matched the sub-expression is split out in a separate field by the
matching algorithms. Marked sub-expressions can also repeated, or referred
to by a back-reference.
</p>
<h5>
<a name="boost_regex.syntax.basic_extended.h5"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.repeats"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.repeats">Repeats:</a>
</h5>
<p>
Any atom (a single character, a marked sub-expression, or a character class)
can be repeated with the <code class="computeroutput"><span class="special">*</span></code>,
<code class="computeroutput"><span class="special">+</span></code>, <code class="computeroutput"><span class="special">?</span></code>,
and <code class="computeroutput"><span class="special">{}</span></code> operators.
</p>
<p>
The <code class="computeroutput"><span class="special">*</span></code> operator will match the
preceding atom <span class="emphasis"><em>zero or more times</em></span>, for example the expression
<code class="computeroutput"><span class="identifier">a</span><span class="special">*</span><span class="identifier">b</span></code> will match any of the following:
</p>
<pre class="programlisting">b
ab
aaaaaaaab
</pre>
<p>
The <code class="computeroutput"><span class="special">+</span></code> operator will match the
preceding atom <span class="emphasis"><em>one or more times</em></span>, for example the expression
a+b will match any of the following:
</p>
<pre class="programlisting">ab
aaaaaaaab
</pre>
<p>
But will not match:
</p>
<pre class="programlisting">b
</pre>
<p>
The <code class="computeroutput"><span class="special">?</span></code> operator will match the
preceding atom <span class="emphasis"><em>zero or one times</em></span>, for example the expression
<code class="computeroutput"><span class="identifier">ca</span><span class="special">?</span><span class="identifier">b</span></code> will match any of the following:
</p>
<pre class="programlisting">cb
cab
</pre>
<p>
But will not match:
</p>
<pre class="programlisting">caab
</pre>
<p>
An atom can also be repeated with a bounded repeat:
</p>
<p>
<code class="computeroutput"><span class="identifier">a</span><span class="special">{</span><span class="identifier">n</span><span class="special">}</span></code> Matches
'a' repeated <span class="emphasis"><em>exactly n times</em></span>.
</p>
<p>
<code class="computeroutput"><span class="identifier">a</span><span class="special">{</span><span class="identifier">n</span><span class="special">,}</span></code> Matches
'a' repeated <span class="emphasis"><em>n or more times</em></span>.
</p>
<p>
<code class="computeroutput"><span class="identifier">a</span><span class="special">{</span><span class="identifier">n</span><span class="special">,</span> <span class="identifier">m</span><span class="special">}</span></code> Matches 'a' repeated <span class="emphasis"><em>between n
and m times inclusive</em></span>.
</p>
<p>
For example:
</p>
<pre class="programlisting">^a{2,3}$</pre>
<p>
Will match either of:
</p>
<pre class="programlisting"><span class="identifier">aa</span>
<span class="identifier">aaa</span>
</pre>
<p>
But neither of:
</p>
<pre class="programlisting"><span class="identifier">a</span>
<span class="identifier">aaaa</span>
</pre>
<p>
It is an error to use a repeat operator, if the preceding construct can not
be repeated, for example:
</p>
<pre class="programlisting"><span class="identifier">a</span><span class="special">(*)</span>
</pre>
<p>
Will raise an error, as there is nothing for the <code class="computeroutput"><span class="special">*</span></code>
operator to be applied to.
</p>
<h5>
<a name="boost_regex.syntax.basic_extended.h6"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.back_references"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.back_references">Back
references:</a>
</h5>
<p>
An escape character followed by a digit <span class="emphasis"><em>n</em></span>, where <span class="emphasis"><em>n</em></span>
is in the range 1-9, matches the same string that was matched by sub-expression
<span class="emphasis"><em>n</em></span>. For example the expression:
</p>
<pre class="programlisting">^(a*).*\1$</pre>
<p>
Will match the string:
</p>
<pre class="programlisting"><span class="identifier">aaabbaaa</span>
</pre>
<p>
But not the string:
</p>
<pre class="programlisting"><span class="identifier">aaabba</span>
</pre>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top"><p>
The POSIX standard does not support back-references for "extended"
regular expressions, this is a compatible extension to that standard.
</p></td></tr>
</table></div>
<h5>
<a name="boost_regex.syntax.basic_extended.h7"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.alternation"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.alternation">Alternation</a>
</h5>
<p>
The <code class="computeroutput"><span class="special">|</span></code> operator will match either
of its arguments, so for example: <code class="computeroutput"><span class="identifier">abc</span><span class="special">|</span><span class="identifier">def</span></code> will
match either "abc" or "def".
</p>
<p>
Parenthesis can be used to group alternations, for example: <code class="computeroutput"><span class="identifier">ab</span><span class="special">(</span><span class="identifier">d</span><span class="special">|</span><span class="identifier">ef</span><span class="special">)</span></code>
will match either of "abd" or "abef".
</p>
<h5>
<a name="boost_regex.syntax.basic_extended.h8"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.character_sets"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.character_sets">Character
sets:</a>
</h5>
<p>
A character set is a bracket-expression starting with [ and ending with ],
it defines a set of characters, and matches any single character that is
a member of that set.
</p>
<p>
A bracket expression may contain any combination of the following:
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h9"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.single_characters"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.single_characters">Single
characters:</a>
</h6>
<p>
For example <code class="computeroutput"><span class="special">[</span><span class="identifier">abc</span><span class="special">]</span></code>, will match any of the characters 'a', 'b',
or 'c'.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h10"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.character_ranges"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.character_ranges">Character
ranges:</a>
</h6>
<p>
For example <code class="computeroutput"><span class="special">[</span><span class="identifier">a</span><span class="special">-</span><span class="identifier">c</span><span class="special">]</span></code>
will match any single character in the range 'a' to 'c'. By default, for
POSIX-Extended regular expressions, a character <span class="emphasis"><em>x</em></span> is
within the range <span class="emphasis"><em>y</em></span> to <span class="emphasis"><em>z</em></span>, if it
collates within that range; this results in locale specific behavior . This
behavior can be turned off by unsetting the <code class="computeroutput"><span class="identifier">collate</span></code>
<a class="link" href="../ref/syntax_option_type.html" title="syntax_option_type">option flag</a> - in
which case whether a character appears within a range is determined by comparing
the code points of the characters only.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h11"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.negation"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.negation">Negation:</a>
</h6>
<p>
If the bracket-expression begins with the ^ character, then it matches the
complement of the characters it contains, for example <code class="computeroutput"><span class="special">[^</span><span class="identifier">a</span><span class="special">-</span><span class="identifier">c</span><span class="special">]</span></code> matches any character that is not in the
range <code class="computeroutput"><span class="identifier">a</span><span class="special">-</span><span class="identifier">c</span></code>.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h12"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.character_classes"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.character_classes">Character
classes:</a>
</h6>
<p>
An expression of the form <code class="computeroutput"><span class="special">[[:</span><span class="identifier">name</span><span class="special">:]]</span></code>
matches the named character class "name", for example <code class="computeroutput"><span class="special">[[:</span><span class="identifier">lower</span><span class="special">:]]</span></code> matches any lower case character. See
<a class="link" href="character_classes.html" title="Character Class Names">character class names</a>.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h13"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.collating_elements"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.collating_elements">Collating
Elements:</a>
</h6>
<p>
An expression of the form <code class="computeroutput"><span class="special">[[.</span><span class="identifier">col</span><span class="special">.]</span></code> matches
the collating element <span class="emphasis"><em>col</em></span>. A collating element is any
single character, or any sequence of characters that collates as a single
unit. Collating elements may also be used as the end point of a range, for
example: <code class="computeroutput"><span class="special">[[.</span><span class="identifier">ae</span><span class="special">.]-</span><span class="identifier">c</span><span class="special">]</span></code>
matches the character sequence "ae", plus any single character
in the range "ae"-c, assuming that "ae" is treated as
a single collating element in the current locale.
</p>
<p>
Collating elements may be used in place of escapes (which are not normally
allowed inside character sets), for example <code class="computeroutput"><span class="special">[[.^.]</span><span class="identifier">abc</span><span class="special">]</span></code> would
match either one of the characters 'abc^'.
</p>
<p>
As an extension, a collating element may also be specified via its <a class="link" href="collating_names.html" title="Collating Names">symbolic name</a>, for example:
</p>
<pre class="programlisting"><span class="special">[[.</span><span class="identifier">NUL</span><span class="special">.]]</span>
</pre>
<p>
matches a NUL character.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h14"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.equivalence_classes"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.equivalence_classes">Equivalence
classes:</a>
</h6>
<p>
An expression of the form <code class="computeroutput"><span class="special">[[=</span><span class="identifier">col</span><span class="special">=]]</span></code>,
matches any character or collating element whose primary sort key is the
same as that for collating element <span class="emphasis"><em>col</em></span>, as with collating
elements the name <span class="emphasis"><em>col</em></span> may be a <a class="link" href="collating_names.html" title="Collating Names">symbolic
name</a>. A primary sort key is one that ignores case, accentation, or
locale-specific tailorings; so for example <code class="computeroutput"><span class="special">[[=</span><span class="identifier">a</span><span class="special">=]]</span></code> matches
any of the characters: a, À, Á, Â, Ã, Ä, Å, A, à, á, â, ã, ä and å. Unfortunately implementation
of this is reliant on the platform's collation and localisation support;
this feature can not be relied upon to work portably across all platforms,
or even all locales on one platform.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h15"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.combinations"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.combinations">Combinations:</a>
</h6>
<p>
All of the above can be combined in one character set declaration, for example:
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">digit</span><span class="special">:]</span><span class="identifier">a</span><span class="special">-</span><span class="identifier">c</span><span class="special">[.</span><span class="identifier">NUL</span><span class="special">.]]</span></code>.
</p>
<h5>
<a name="boost_regex.syntax.basic_extended.h16"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.escapes"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.escapes">Escapes</a>
</h5>
<p>
The POSIX standard defines no escape sequences for POSIX-Extended regular
expressions, except that:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Any special character preceded by an escape shall match itself.
</li>
<li class="listitem">
The effect of any ordinary character being preceded by an escape is undefined.
</li>
<li class="listitem">
An escape inside a character class declaration shall match itself: in
other words the escape character is not "special" inside a
character class declaration; so <code class="computeroutput"><span class="special">[\^]</span></code>
will match either a literal '\' or a '^'.
</li>
</ul></div>
<p>
However, that's rather restrictive, so the following standard-compatible
extensions are also supported by Boost.Regex:
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h17"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.escapes_matching_a_specific_char"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.escapes_matching_a_specific_char">Escapes
matching a specific character</a>
</h6>
<p>
The following escape sequences are all synonyms for single characters:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Escape
</p>
</th>
<th>
<p>
Character
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
\a
</p>
</td>
<td>
<p>
'\a'
</p>
</td>
</tr>
<tr>
<td>
<p>
\e
</p>
</td>
<td>
<p>
0x1B
</p>
</td>
</tr>
<tr>
<td>
<p>
\f
</p>
</td>
<td>
<p>
\f
</p>
</td>
</tr>
<tr>
<td>
<p>
\n
</p>
</td>
<td>
<p>
\n
</p>
</td>
</tr>
<tr>
<td>
<p>
\r
</p>
</td>
<td>
<p>
\r
</p>
</td>
</tr>
<tr>
<td>
<p>
\t
</p>
</td>
<td>
<p>
\t
</p>
</td>
</tr>
<tr>
<td>
<p>
\v
</p>
</td>
<td>
<p>
\v
</p>
</td>
</tr>
<tr>
<td>
<p>
\b
</p>
</td>
<td>
<p>
\b (but only inside a character class declaration).
</p>
</td>
</tr>
<tr>
<td>
<p>
\cX
</p>
</td>
<td>
<p>
An ASCII escape sequence - the character whose code point is X
% 32
</p>
</td>
</tr>
<tr>
<td>
<p>
\xdd
</p>
</td>
<td>
<p>
A hexadecimal escape sequence - matches the single character whose
code point is 0xdd.
</p>
</td>
</tr>
<tr>
<td>
<p>
\x{dddd}
</p>
</td>
<td>
<p>
A hexadecimal escape sequence - matches the single character whose
code point is 0xdddd.
</p>
</td>
</tr>
<tr>
<td>
<p>
\0ddd
</p>
</td>
<td>
<p>
An octal escape sequence - matches the single character whose code
point is 0ddd.
</p>
</td>
</tr>
<tr>
<td>
<p>
\N{Name}
</p>
</td>
<td>
<p>
Matches the single character which has the symbolic name <span class="emphasis"><em>Name</em></span>.
For example <code class="computeroutput"><span class="special">\\</span><span class="identifier">N</span><span class="special">{</span><span class="identifier">newline</span><span class="special">}</span></code> matches the single character \n.
</p>
</td>
</tr>
</tbody>
</table></div>
<h6>
<a name="boost_regex.syntax.basic_extended.h18"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.single_character_character_class"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.single_character_character_class">"Single
character" character classes:</a>
</h6>
<p>
Any escaped character <span class="emphasis"><em>x</em></span>, if <span class="emphasis"><em>x</em></span> is
the name of a character class shall match any character that is a member
of that class, and any escaped character <span class="emphasis"><em>X</em></span>, if <span class="emphasis"><em>x</em></span>
is the name of a character class, shall match any character not in that class.
</p>
<p>
The following are supported by default:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Escape sequence
</p>
</th>
<th>
<p>
Equivalent to
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">d</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">digit</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">l</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">lower</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">s</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">space</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">u</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">upper</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">w</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">word</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">D</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[^[:</span><span class="identifier">digit</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">L</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[^[:</span><span class="identifier">lower</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">S</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[^[:</span><span class="identifier">space</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">U</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[^[:</span><span class="identifier">upper</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">W</span></code>
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[^[:</span><span class="identifier">word</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
<h6>
<a name="boost_regex.syntax.basic_extended.h19"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.character_properties"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.character_properties">Character
Properties</a>
</h6>
<p>
The character property names in the following table are all equivalent to
the names used in character classes.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Form
</p>
</th>
<th>
<p>
Description
</p>
</th>
<th>
<p>
Equivalent character set form
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">pX</span></code>
</p>
</td>
<td>
<p>
Matches any character that has the property X.
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">X</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">p</span><span class="special">{</span><span class="identifier">Name</span><span class="special">}</span></code>
</p>
</td>
<td>
<p>
Matches any character that has the property Name.
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[[:</span><span class="identifier">Name</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">PX</span></code>
</p>
</td>
<td>
<p>
Matches any character that does not have the property X.
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[^[:</span><span class="identifier">X</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">P</span><span class="special">{</span><span class="identifier">Name</span><span class="special">}</span></code>
</p>
</td>
<td>
<p>
Matches any character that does not have the property Name.
</p>
</td>
<td>
<p>
<code class="computeroutput"><span class="special">[^[:</span><span class="identifier">Name</span><span class="special">:]]</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
For example <code class="computeroutput"><span class="special">\</span><span class="identifier">pd</span></code>
matches any "digit" character, as does <code class="computeroutput"><span class="special">\</span><span class="identifier">p</span><span class="special">{</span><span class="identifier">digit</span><span class="special">}</span></code>.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h20"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.word_boundaries"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.word_boundaries">Word
Boundaries</a>
</h6>
<p>
The following escape sequences match the boundaries of words:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Escape
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\<</span></code>
</p>
</td>
<td>
<p>
Matches the start of a word.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\></span></code>
</p>
</td>
<td>
<p>
Matches the end of a word.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">b</span></code>
</p>
</td>
<td>
<p>
Matches a word boundary (the start or end of a word).
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">B</span></code>
</p>
</td>
<td>
<p>
Matches only when not at a word boundary.
</p>
</td>
</tr>
</tbody>
</table></div>
<h6>
<a name="boost_regex.syntax.basic_extended.h21"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.buffer_boundaries"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.buffer_boundaries">Buffer
boundaries</a>
</h6>
<p>
The following match only at buffer boundaries: a "buffer" in this
context is the whole of the input text that is being matched against (note
that ^ and $ may match embedded newlines within the text).
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Escape
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
\`
</p>
</td>
<td>
<p>
Matches at the start of a buffer only.
</p>
</td>
</tr>
<tr>
<td>
<p>
\'
</p>
</td>
<td>
<p>
Matches at the end of a buffer only.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">A</span></code>
</p>
</td>
<td>
<p>
Matches at the start of a buffer only (the same as \`).
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">z</span></code>
</p>
</td>
<td>
<p>
Matches at the end of a buffer only (the same as \').
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">Z</span></code>
</p>
</td>
<td>
<p>
Matches an optional sequence of newlines at the end of a buffer:
equivalent to the regular expression <code class="computeroutput"><span class="special">\</span><span class="identifier">n</span><span class="special">*\</span><span class="identifier">z</span></code>
</p>
</td>
</tr>
</tbody>
</table></div>
<h6>
<a name="boost_regex.syntax.basic_extended.h22"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.continuation_escape"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.continuation_escape">Continuation
Escape</a>
</h6>
<p>
The sequence <code class="computeroutput"><span class="special">\</span><span class="identifier">G</span></code>
matches only at the end of the last match found, or at the start of the text
being matched if no previous match was found. This escape useful if you're
iterating over the matches contained within a text, and you want each subsequence
match to start where the last one ended.
</p>
<h6>
<a name="boost_regex.syntax.basic_extended.h23"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.quoting_escape"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.quoting_escape">Quoting
escape</a>
</h6>
<p>
The escape sequence <code class="computeroutput"><span class="special">\</span><span class="identifier">Q</span></code>
begins a "quoted sequence": all the subsequent characters are treated
as literals, until either the end of the regular expression or <code class="computeroutput"><span class="special">\</span><span class="identifier">E</span></code> is found.
For example the expression: <code class="computeroutput"><span class="special">\</span><span class="identifier">Q</span><span class="special">\*+\</span><span class="identifier">Ea</span><span class="special">+</span></code> would match either of:
</p>
<pre class="programlisting"><span class="special">\*+</span><span class="identifier">a</span>
<span class="special">\*+</span><span class="identifier">aaa</span>
</pre>
<h6>
<a name="boost_regex.syntax.basic_extended.h24"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.unicode_escapes"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.unicode_escapes">Unicode
escapes</a>
</h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Escape
</p>
</th>
<th>
<p>
Meaning
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">C</span></code>
</p>
</td>
<td>
<p>
Matches a single code point: in Boost regex this has exactly the
same effect as a "." operator.
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="special">\</span><span class="identifier">X</span></code>
</p>
</td>
<td>
<p>
Matches a combining character sequence: that is any non-combining
character followed by a sequence of zero or more combining characters.
</p>
</td>
</tr>
</tbody>
</table></div>
<h6>
<a name="boost_regex.syntax.basic_extended.h25"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.any_other_escape"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.any_other_escape">Any
other escape</a>
</h6>
<p>
Any other escape sequence matches the character that is escaped, for example
\@ matches a literal '@'.
</p>
<h5>
<a name="boost_regex.syntax.basic_extended.h26"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.operator_precedence"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.operator_precedence">Operator
precedence</a>
</h5>
<p>
The order of precedence for of operators is as follows:
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
Collation-related bracket symbols <code class="computeroutput"><span class="special">[==]</span>
<span class="special">[::]</span> <span class="special">[..]</span></code>
</li>
<li class="listitem">
Escaped characters <code class="computeroutput"><span class="special">\</span></code>
</li>
<li class="listitem">
Character set (bracket expression) <code class="computeroutput"><span class="special">[]</span></code>
</li>
<li class="listitem">
Grouping <code class="computeroutput"><span class="special">()</span></code>
</li>
<li class="listitem">
Single-character-ERE duplication <code class="computeroutput"><span class="special">*</span>
<span class="special">+</span> <span class="special">?</span>
<span class="special">{</span><span class="identifier">m</span><span class="special">,</span><span class="identifier">n</span><span class="special">}</span></code>
</li>
<li class="listitem">
Concatenation
</li>
<li class="listitem">
Anchoring ^$
</li>
<li class="listitem">
Alternation <code class="computeroutput"><span class="special">|</span></code>
</li>
</ol></div>
<h5>
<a name="boost_regex.syntax.basic_extended.h27"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.what_gets_matched"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.what_gets_matched">What
Gets Matched</a>
</h5>
<p>
When there is more that one way to match a regular expression, the "best"
possible match is obtained using the <a class="link" href="leftmost_longest_rule.html" title="The Leftmost Longest Rule">leftmost-longest
rule</a>.
</p>
<h4>
<a name="boost_regex.syntax.basic_extended.h28"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.variations"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.variations">Variations</a>
</h4>
<h5>
<a name="boost_regex.syntax.basic_extended.h29"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.egrep"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.egrep">Egrep</a>
</h5>
<p>
When an expression is compiled with the <a class="link" href="../ref/syntax_option_type.html" title="syntax_option_type">flag
<code class="computeroutput"><span class="identifier">egrep</span></code></a> set, then the
expression is treated as a newline separated list of <a class="link" href="basic_extended.html#boost_regex.posix_extended_syntax">POSIX-Extended
expressions</a>, a match is found if any of the expressions in the list
match, for example:
</p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span> <span class="identifier">e</span><span class="special">(</span><span class="string">"abc\ndef"</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span><span class="special">::</span><span class="identifier">egrep</span><span class="special">);</span>
</pre>
<p>
will match either of the POSIX-Basic expressions "abc" or "def".
</p>
<p>
As its name suggests, this behavior is consistent with the Unix utility
<code class="computeroutput"><span class="identifier">egrep</span></code>, and with grep when
used with the -E option.
</p>
<h5>
<a name="boost_regex.syntax.basic_extended.h30"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.awk"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.awk">awk</a>
</h5>
<p>
In addition to the <a class="link" href="basic_extended.html#boost_regex.posix_extended_syntax">POSIX-Extended
features</a> the escape character is special inside a character class
declaration.
</p>
<p>
In addition, some escape sequences that are not defined as part of POSIX-Extended
specification are required to be supported - however Boost.Regex supports
these by default anyway.
</p>
<h4>
<a name="boost_regex.syntax.basic_extended.h31"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.options"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.options">Options</a>
</h4>
<p>
There are a <a class="link" href="../ref/syntax_option_type/syntax_option_type_extended.html" title="Options for POSIX Extended Regular Expressions">variety
of flags</a> that may be combined with the <code class="computeroutput"><span class="identifier">extended</span></code>
and <code class="computeroutput"><span class="identifier">egrep</span></code> options when constructing
the regular expression, in particular note that the <a class="link" href="../ref/syntax_option_type/syntax_option_type_extended.html" title="Options for POSIX Extended Regular Expressions"><code class="computeroutput"><span class="identifier">newline_alt</span></code></a> option alters the syntax,
while the <a class="link" href="../ref/syntax_option_type/syntax_option_type_extended.html" title="Options for POSIX Extended Regular Expressions"><code class="computeroutput"><span class="identifier">collate</span></code>, <code class="computeroutput"><span class="identifier">nosubs</span></code>
and <code class="computeroutput"><span class="identifier">icase</span></code> options</a>
modify how the case and locale sensitivity are to be applied.
</p>
<h4>
<a name="boost_regex.syntax.basic_extended.h32"></a>
<span class="phrase"><a name="boost_regex.syntax.basic_extended.references"></a></span><a class="link" href="basic_extended.html#boost_regex.syntax.basic_extended.references">References</a>
</h4>
<p>
<a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap09.html" target="_top">IEEE
Std 1003.1-2001, Portable Operating System Interface (POSIX ), Base Definitions
and Headers, Section 9, Regular Expressions.</a>
</p>
<p>
<a href="http://www.opengroup.org/onlinepubs/000095399/utilities/grep.html" target="_top">IEEE
Std 1003.1-2001, Portable Operating System Interface (POSIX ), Shells and
Utilities, Section 4, Utilities, egrep.</a>
</p>
<p>
<a href="http://www.opengroup.org/onlinepubs/000095399/utilities/awk.html" target="_top">IEEE
Std 1003.1-2001, Portable Operating System Interface (POSIX ), Shells and
Utilities, Section 4, Utilities, awk.</a>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 1998-2013 John Maddock<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="perl_syntax.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../syntax.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="basic_syntax.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
|