1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Perl Regular Expression Syntax</title> 5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Boost.Regex 5.1.4"> 8<link rel="up" href="../syntax.html" title="Regular Expression Syntax"> 9<link rel="prev" href="../syntax.html" title="Regular Expression Syntax"> 10<link rel="next" href="basic_extended.html" title="POSIX Extended Regular Expression Syntax"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="../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_extended.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_regex.syntax.perl_syntax"></a><a class="link" href="perl_syntax.html" title="Perl Regular Expression Syntax">Perl Regular Expression 28 Syntax</a> 29</h3></div></div></div> 30<h4> 31<a name="boost_regex.syntax.perl_syntax.h0"></a> 32 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.synopsis"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.synopsis">Synopsis</a> 33 </h4> 34<p> 35 The Perl regular expression syntax is based on that used by the programming 36 language Perl . Perl regular expressions are the default behavior in Boost.Regex 37 or you can pass the flag <code class="literal">perl</code> to the <a class="link" href="../ref/basic_regex.html" title="basic_regex"><code class="computeroutput"><span class="identifier">basic_regex</span></code></a> constructor, for example: 38 </p> 39<pre class="programlisting"><span class="comment">// e1 is a case sensitive Perl regular expression: </span> 40<span class="comment">// since Perl is the default option there's no need to explicitly specify the syntax used here:</span> 41<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> 42<span class="comment">// e2 a case insensitive Perl regular expression:</span> 43<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">perl</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> 44</pre> 45<h4> 46<a name="boost_regex.syntax.perl_syntax.h1"></a> 47 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.perl_regular_expression_syntax"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.perl_regular_expression_syntax">Perl 48 Regular Expression Syntax</a> 49 </h4> 50<p> 51 In Perl regular expressions, all characters match themselves except for the 52 following special characters: 53 </p> 54<pre class="programlisting">.[{}()\*+?|^$</pre> 55<p> 56 Other characters are special only in certain situations - for example <code class="computeroutput"><span class="special">]</span></code> is special only after an opening <code class="computeroutput"><span class="special">[</span></code>. 57 </p> 58<h5> 59<a name="boost_regex.syntax.perl_syntax.h2"></a> 60 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.wildcard"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.wildcard">Wildcard</a> 61 </h5> 62<p> 63 The single character '.' when used outside of a character set will match 64 any single character except: 65 </p> 66<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 67<li class="listitem"> 68 The NULL character when the <a class="link" href="../ref/match_flag_type.html" title="match_flag_type">flag 69 <code class="literal">match_not_dot_null</code></a> is passed to the matching 70 algorithms. 71 </li> 72<li class="listitem"> 73 The newline character when the <a class="link" href="../ref/match_flag_type.html" title="match_flag_type">flag 74 <code class="literal">match_not_dot_newline</code></a> is passed to the matching 75 algorithms. 76 </li> 77</ul></div> 78<h5> 79<a name="boost_regex.syntax.perl_syntax.h3"></a> 80 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.anchors"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.anchors">Anchors</a> 81 </h5> 82<p> 83 A '^' character shall match the start of a line. 84 </p> 85<p> 86 A '$' character shall match the end of a line. 87 </p> 88<h5> 89<a name="boost_regex.syntax.perl_syntax.h4"></a> 90 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.marked_sub_expressions"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.marked_sub_expressions">Marked sub-expressions</a> 91 </h5> 92<p> 93 A section beginning <code class="literal">(</code> and ending <code class="literal">)</code> 94 acts as a marked sub-expression. Whatever matched the sub-expression is split 95 out in a separate field by the matching algorithms. Marked sub-expressions 96 can also repeated, or referred to by a back-reference. 97 </p> 98<h5> 99<a name="boost_regex.syntax.perl_syntax.h5"></a> 100 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.non_marking_grouping"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.non_marking_grouping">Non-marking 101 grouping</a> 102 </h5> 103<p> 104 A marked sub-expression is useful to lexically group part of a regular expression, 105 but has the side-effect of spitting out an extra field in the result. As 106 an alternative you can lexically group part of a regular expression, without 107 generating a marked sub-expression by using <code class="literal">(?:</code> and <code class="literal">)</code> 108 , for example <code class="literal">(?:ab)+</code> will repeat <code class="literal">ab</code> 109 without splitting out any separate sub-expressions. 110 </p> 111<h5> 112<a name="boost_regex.syntax.perl_syntax.h6"></a> 113 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.repeats"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.repeats">Repeats</a> 114 </h5> 115<p> 116 Any atom (a single character, a marked sub-expression, or a character class) 117 can be repeated with the <code class="literal">*</code>, <code class="literal">+</code>, <code class="literal">?</code>, 118 and <code class="literal">{}</code> operators. 119 </p> 120<p> 121 The <code class="literal">*</code> operator will match the preceding atom zero or more 122 times, for example the expression <code class="literal">a*b</code> will match any of 123 the following: 124 </p> 125<pre class="programlisting"><span class="identifier">b</span> 126<span class="identifier">ab</span> 127<span class="identifier">aaaaaaaab</span> 128</pre> 129<p> 130 The <code class="literal">+</code> operator will match the preceding atom one or more 131 times, for example the expression <code class="literal">a+b</code> will match any of 132 the following: 133 </p> 134<pre class="programlisting"><span class="identifier">ab</span> 135<span class="identifier">aaaaaaaab</span> 136</pre> 137<p> 138 But will not match: 139 </p> 140<pre class="programlisting"><span class="identifier">b</span> 141</pre> 142<p> 143 The <code class="literal">?</code> operator will match the preceding atom zero or one 144 times, for example the expression ca?b will match any of the following: 145 </p> 146<pre class="programlisting"><span class="identifier">cb</span> 147<span class="identifier">cab</span> 148</pre> 149<p> 150 But will not match: 151 </p> 152<pre class="programlisting"><span class="identifier">caab</span> 153</pre> 154<p> 155 An atom can also be repeated with a bounded repeat: 156 </p> 157<p> 158 <code class="literal">a{n}</code> Matches 'a' repeated exactly n times. 159 </p> 160<p> 161 <code class="literal">a{n,}</code> Matches 'a' repeated n or more times. 162 </p> 163<p> 164 <code class="literal">a{n, m}</code> Matches 'a' repeated between n and m times inclusive. 165 </p> 166<p> 167 For example: 168 </p> 169<pre class="programlisting">^a{2,3}$</pre> 170<p> 171 Will match either of: 172 </p> 173<pre class="programlisting"><span class="identifier">aa</span> 174<span class="identifier">aaa</span> 175</pre> 176<p> 177 But neither of: 178 </p> 179<pre class="programlisting"><span class="identifier">a</span> 180<span class="identifier">aaaa</span> 181</pre> 182<p> 183 Note that the "{" and "}" characters will treated as 184 ordinary literals when used in a context that is not a repeat: this matches 185 Perl 5.x behavior. For example in the expressions "ab{1", "ab1}" 186 and "a{b}c" the curly brackets are all treated as literals and 187 <span class="emphasis"><em>no error will be raised</em></span>. 188 </p> 189<p> 190 It is an error to use a repeat operator, if the preceding construct can not 191 be repeated, for example: 192 </p> 193<pre class="programlisting"><span class="identifier">a</span><span class="special">(*)</span> 194</pre> 195<p> 196 Will raise an error, as there is nothing for the <code class="literal">*</code> operator 197 to be applied to. 198 </p> 199<h5> 200<a name="boost_regex.syntax.perl_syntax.h7"></a> 201 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.non_greedy_repeats"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.non_greedy_repeats">Non 202 greedy repeats</a> 203 </h5> 204<p> 205 The normal repeat operators are "greedy", that is to say they will 206 consume as much input as possible. There are non-greedy versions available 207 that will consume as little input as possible while still producing a match. 208 </p> 209<p> 210 <code class="literal">*?</code> Matches the previous atom zero or more times, while 211 consuming as little input as possible. 212 </p> 213<p> 214 <code class="literal">+?</code> Matches the previous atom one or more times, while 215 consuming as little input as possible. 216 </p> 217<p> 218 <code class="literal">??</code> Matches the previous atom zero or one times, while 219 consuming as little input as possible. 220 </p> 221<p> 222 <code class="literal">{n,}?</code> Matches the previous atom n or more times, while 223 consuming as little input as possible. 224 </p> 225<p> 226 <code class="literal">{n,m}?</code> Matches the previous atom between n and m times, 227 while consuming as little input as possible. 228 </p> 229<h5> 230<a name="boost_regex.syntax.perl_syntax.h8"></a> 231 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.possessive_repeats"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.possessive_repeats">Possessive 232 repeats</a> 233 </h5> 234<p> 235 By default when a repeated pattern does not match then the engine will backtrack 236 until a match is found. However, this behaviour can sometime be undesireble 237 so there are also "possessive" repeats: these match as much as 238 possible and do not then allow backtracking if the rest of the expression 239 fails to match. 240 </p> 241<p> 242 <code class="literal">*+</code> Matches the previous atom zero or more times, while 243 giving nothing back. 244 </p> 245<p> 246 <code class="literal">++</code> Matches the previous atom one or more times, while 247 giving nothing back. 248 </p> 249<p> 250 <code class="literal">?+</code> Matches the previous atom zero or one times, while 251 giving nothing back. 252 </p> 253<p> 254 <code class="literal">{n,}+</code> Matches the previous atom n or more times, while 255 giving nothing back. 256 </p> 257<p> 258 <code class="literal">{n,m}+</code> Matches the previous atom between n and m times, 259 while giving nothing back. 260 </p> 261<h5> 262<a name="boost_regex.syntax.perl_syntax.h9"></a> 263 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.back_references"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.back_references">Back 264 references</a> 265 </h5> 266<p> 267 An escape character followed by a digit <span class="emphasis"><em>n</em></span>, where <span class="emphasis"><em>n</em></span> 268 is in the range 1-9, matches the same string that was matched by sub-expression 269 <span class="emphasis"><em>n</em></span>. For example the expression: 270 </p> 271<pre class="programlisting">^(a*)[^a]*\1$</pre> 272<p> 273 Will match the string: 274 </p> 275<pre class="programlisting"><span class="identifier">aaabbaaa</span> 276</pre> 277<p> 278 But not the string: 279 </p> 280<pre class="programlisting"><span class="identifier">aaabba</span> 281</pre> 282<p> 283 You can also use the \g escape for the same function, for example: 284 </p> 285<div class="informaltable"><table class="table"> 286<colgroup> 287<col> 288<col> 289</colgroup> 290<thead><tr> 291<th> 292 <p> 293 Escape 294 </p> 295 </th> 296<th> 297 <p> 298 Meaning 299 </p> 300 </th> 301</tr></thead> 302<tbody> 303<tr> 304<td> 305 <p> 306 <code class="literal">\g1</code> 307 </p> 308 </td> 309<td> 310 <p> 311 Match whatever matched sub-expression 1 312 </p> 313 </td> 314</tr> 315<tr> 316<td> 317 <p> 318 <code class="literal">\g{1}</code> 319 </p> 320 </td> 321<td> 322 <p> 323 Match whatever matched sub-expression 1: this form allows for safer 324 parsing of the expression in cases like <code class="literal">\g{1}2</code> 325 or for indexes higher than 9 as in <code class="literal">\g{1234}</code> 326 </p> 327 </td> 328</tr> 329<tr> 330<td> 331 <p> 332 <code class="literal">\g-1</code> 333 </p> 334 </td> 335<td> 336 <p> 337 Match whatever matched the last opened sub-expression 338 </p> 339 </td> 340</tr> 341<tr> 342<td> 343 <p> 344 <code class="literal">\g{-2}</code> 345 </p> 346 </td> 347<td> 348 <p> 349 Match whatever matched the last but one opened sub-expression 350 </p> 351 </td> 352</tr> 353<tr> 354<td> 355 <p> 356 <code class="literal">\g{one}</code> 357 </p> 358 </td> 359<td> 360 <p> 361 Match whatever matched the sub-expression named "one" 362 </p> 363 </td> 364</tr> 365</tbody> 366</table></div> 367<p> 368 Finally the \k escape can be used to refer to named subexpressions, for example 369 <code class="literal">\k<two></code> will match whatever matched the subexpression 370 named "two". 371 </p> 372<h5> 373<a name="boost_regex.syntax.perl_syntax.h10"></a> 374 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.alternation"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.alternation">Alternation</a> 375 </h5> 376<p> 377 The <code class="literal">|</code> operator will match either of its arguments, so 378 for example: <code class="literal">abc|def</code> will match either "abc" 379 or "def". 380 </p> 381<p> 382 Parenthesis can be used to group alternations, for example: <code class="literal">ab(d|ef)</code> 383 will match either of "abd" or "abef". 384 </p> 385<p> 386 Empty alternatives are not allowed (these are almost always a mistake), but 387 if you really want an empty alternative use <code class="literal">(?:)</code> as a 388 placeholder, for example: 389 </p> 390<p> 391 <code class="literal">|abc</code> is not a valid expression, but 392 </p> 393<p> 394 <code class="literal">(?:)|abc</code> is and is equivalent, also the expression: 395 </p> 396<p> 397 <code class="literal">(?:abc)??</code> has exactly the same effect. 398 </p> 399<h5> 400<a name="boost_regex.syntax.perl_syntax.h11"></a> 401 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.character_sets"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.character_sets">Character 402 sets</a> 403 </h5> 404<p> 405 A character set is a bracket-expression starting with <code class="literal">[] and ending 406 with <code class="literal"></code></code>, it defines a set of characters, and matches 407 any single character that is a member of that set. 408 </p> 409<p> 410 A bracket expression may contain any combination of the following: 411 </p> 412<h6> 413<a name="boost_regex.syntax.perl_syntax.h12"></a> 414 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.single_characters"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.single_characters">Single 415 characters</a> 416 </h6> 417<p> 418 For example <code class="literal">[abc]</code>, will match any of the characters 'a', 419 'b', or 'c'. 420 </p> 421<h6> 422<a name="boost_regex.syntax.perl_syntax.h13"></a> 423 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.character_ranges"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.character_ranges">Character 424 ranges</a> 425 </h6> 426<p> 427 For example <code class="literal">[a-c]</code> will match any single character in the 428 range 'a' to 'c'. By default, for Perl regular expressions, a character x 429 is within the range y to z, if the code point of the character lies within 430 the codepoints of the endpoints of the range. Alternatively, if you set the 431 <a class="link" href="../ref/syntax_option_type/syntax_option_type_perl.html" title="Options for Perl Regular Expressions"><code class="literal">collate</code> 432 flag</a> when constructing the regular expression, then ranges are locale 433 sensitive. 434 </p> 435<h6> 436<a name="boost_regex.syntax.perl_syntax.h14"></a> 437 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.negation"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.negation">Negation</a> 438 </h6> 439<p> 440 If the bracket-expression begins with the ^ character, then it matches the 441 complement of the characters it contains, for example <code class="literal">[^a-c]</code> 442 matches any character that is not in the range <code class="literal">a-c</code>. 443 </p> 444<h6> 445<a name="boost_regex.syntax.perl_syntax.h15"></a> 446 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.character_classes"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.character_classes">Character 447 classes</a> 448 </h6> 449<p> 450 An expression of the form <code class="literal">[[:name:]]</code> matches the named 451 character class "name", for example <code class="literal">[[:lower:]]</code> 452 matches any lower case character. See <a class="link" href="character_classes.html" title="Character Class Names">character 453 class names</a>. 454 </p> 455<h6> 456<a name="boost_regex.syntax.perl_syntax.h16"></a> 457 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.collating_elements"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.collating_elements">Collating 458 Elements</a> 459 </h6> 460<p> 461 An expression of the form <code class="literal">[[.col.]]</code> matches the collating 462 element <span class="emphasis"><em>col</em></span>. A collating element is any single character, 463 or any sequence of characters that collates as a single unit. Collating elements 464 may also be used as the end point of a range, for example: <code class="literal">[[.ae.]-c]</code> 465 matches the character sequence "ae", plus any single character 466 in the range "ae"-c, assuming that "ae" is treated as 467 a single collating element in the current locale. 468 </p> 469<p> 470 As an extension, a collating element may also be specified via it's <a class="link" href="collating_names.html" title="Collating Names">symbolic name</a>, for example: 471 </p> 472<pre class="programlisting"><span class="special">[[.</span><span class="identifier">NUL</span><span class="special">.]]</span> 473</pre> 474<p> 475 matches a <code class="literal">\0</code> character. 476 </p> 477<h6> 478<a name="boost_regex.syntax.perl_syntax.h17"></a> 479 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.equivalence_classes"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.equivalence_classes">Equivalence 480 classes</a> 481 </h6> 482<p> 483 An expression of the form <code class="literal">[[=col=]]</code>, matches any character 484 or collating element whose primary sort key is the same as that for collating 485 element <span class="emphasis"><em>col</em></span>, as with collating elements the name <span class="emphasis"><em>col</em></span> 486 may be a <a class="link" href="collating_names.html" title="Collating Names">symbolic name</a>. 487 A primary sort key is one that ignores case, accentation, or locale-specific 488 tailorings; so for example <code class="computeroutput"><span class="special">[[=</span><span class="identifier">a</span><span class="special">=]]</span></code> matches 489 any of the characters: a, À, Á, Â, Ã, Ä, Å, A, à, á, â, ã, ä and å. Unfortunately implementation 490 of this is reliant on the platform's collation and localisation support; 491 this feature can not be relied upon to work portably across all platforms, 492 or even all locales on one platform. 493 </p> 494<h6> 495<a name="boost_regex.syntax.perl_syntax.h18"></a> 496 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.escaped_characters"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.escaped_characters">Escaped 497 Characters</a> 498 </h6> 499<p> 500 All the escape sequences that match a single character, or a single character 501 class are permitted within a character class definition. For example <code class="computeroutput"><span class="special">[\[\]]</span></code> would match either of <code class="computeroutput"><span class="special">[</span></code> or <code class="computeroutput"><span class="special">]</span></code> 502 while <code class="computeroutput"><span class="special">[\</span><span class="identifier">W</span><span class="special">\</span><span class="identifier">d</span><span class="special">]</span></code> 503 would match any character that is either a "digit", <span class="emphasis"><em>or</em></span> 504 is <span class="emphasis"><em>not</em></span> a "word" character. 505 </p> 506<h6> 507<a name="boost_regex.syntax.perl_syntax.h19"></a> 508 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.combinations"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.combinations">Combinations</a> 509 </h6> 510<p> 511 All of the above can be combined in one character set declaration, for example: 512 <code class="literal">[[:digit:]a-c[.NUL.]]</code>. 513 </p> 514<h5> 515<a name="boost_regex.syntax.perl_syntax.h20"></a> 516 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.escapes"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.escapes">Escapes</a> 517 </h5> 518<p> 519 Any special character preceded by an escape shall match itself. 520 </p> 521<p> 522 The following escape sequences are all synonyms for single characters: 523 </p> 524<div class="informaltable"><table class="table"> 525<colgroup> 526<col> 527<col> 528</colgroup> 529<thead><tr> 530<th> 531 <p> 532 Escape 533 </p> 534 </th> 535<th> 536 <p> 537 Character 538 </p> 539 </th> 540</tr></thead> 541<tbody> 542<tr> 543<td> 544 <p> 545 <code class="literal">\a</code> 546 </p> 547 </td> 548<td> 549 <p> 550 <code class="literal">\a</code> 551 </p> 552 </td> 553</tr> 554<tr> 555<td> 556 <p> 557 <code class="literal">\e</code> 558 </p> 559 </td> 560<td> 561 <p> 562 <code class="literal">0x1B</code> 563 </p> 564 </td> 565</tr> 566<tr> 567<td> 568 <p> 569 <code class="literal">\f</code> 570 </p> 571 </td> 572<td> 573 <p> 574 <code class="literal">\f</code> 575 </p> 576 </td> 577</tr> 578<tr> 579<td> 580 <p> 581 <code class="literal">\n</code> 582 </p> 583 </td> 584<td> 585 <p> 586 <code class="literal">\n</code> 587 </p> 588 </td> 589</tr> 590<tr> 591<td> 592 <p> 593 <code class="literal">\r</code> 594 </p> 595 </td> 596<td> 597 <p> 598 <code class="literal">\r</code> 599 </p> 600 </td> 601</tr> 602<tr> 603<td> 604 <p> 605 <code class="literal">\t</code> 606 </p> 607 </td> 608<td> 609 <p> 610 <code class="literal">\t</code> 611 </p> 612 </td> 613</tr> 614<tr> 615<td> 616 <p> 617 <code class="literal">\v</code> 618 </p> 619 </td> 620<td> 621 <p> 622 <code class="literal">\v</code> 623 </p> 624 </td> 625</tr> 626<tr> 627<td> 628 <p> 629 <code class="literal">\b</code> 630 </p> 631 </td> 632<td> 633 <p> 634 <code class="literal">\b</code> (but only inside a character class declaration). 635 </p> 636 </td> 637</tr> 638<tr> 639<td> 640 <p> 641 <code class="literal">\cX</code> 642 </p> 643 </td> 644<td> 645 <p> 646 An ASCII escape sequence - the character whose code point is X 647 % 32 648 </p> 649 </td> 650</tr> 651<tr> 652<td> 653 <p> 654 <code class="literal">\xdd</code> 655 </p> 656 </td> 657<td> 658 <p> 659 A hexadecimal escape sequence - matches the single character whose 660 code point is 0xdd. 661 </p> 662 </td> 663</tr> 664<tr> 665<td> 666 <p> 667 <code class="literal">\x{dddd}</code> 668 </p> 669 </td> 670<td> 671 <p> 672 A hexadecimal escape sequence - matches the single character whose 673 code point is 0xdddd. 674 </p> 675 </td> 676</tr> 677<tr> 678<td> 679 <p> 680 <code class="literal">\0ddd</code> 681 </p> 682 </td> 683<td> 684 <p> 685 An octal escape sequence - matches the single character whose code 686 point is 0ddd. 687 </p> 688 </td> 689</tr> 690<tr> 691<td> 692 <p> 693 <code class="literal">\N{name}</code> 694 </p> 695 </td> 696<td> 697 <p> 698 Matches the single character which has the <a class="link" href="collating_names.html" title="Collating Names">symbolic 699 name</a> <span class="emphasis"><em>name</em></span>. For example <code class="literal">\N{newline}</code> 700 matches the single character \n. 701 </p> 702 </td> 703</tr> 704</tbody> 705</table></div> 706<h6> 707<a name="boost_regex.syntax.perl_syntax.h21"></a> 708 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.single_character_character_class"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.single_character_character_class">"Single 709 character" character classes:</a> 710 </h6> 711<p> 712 Any escaped character <span class="emphasis"><em>x</em></span>, if <span class="emphasis"><em>x</em></span> is 713 the name of a character class shall match any character that is a member 714 of that class, and any escaped character <span class="emphasis"><em>X</em></span>, if <span class="emphasis"><em>x</em></span> 715 is the name of a character class, shall match any character not in that class. 716 </p> 717<p> 718 The following are supported by default: 719 </p> 720<div class="informaltable"><table class="table"> 721<colgroup> 722<col> 723<col> 724</colgroup> 725<thead><tr> 726<th> 727 <p> 728 Escape sequence 729 </p> 730 </th> 731<th> 732 <p> 733 Equivalent to 734 </p> 735 </th> 736</tr></thead> 737<tbody> 738<tr> 739<td> 740 <p> 741 <code class="computeroutput"><span class="special">\</span><span class="identifier">d</span></code> 742 </p> 743 </td> 744<td> 745 <p> 746 <code class="computeroutput"><span class="special">[[:</span><span class="identifier">digit</span><span class="special">:]]</span></code> 747 </p> 748 </td> 749</tr> 750<tr> 751<td> 752 <p> 753 <code class="computeroutput"><span class="special">\</span><span class="identifier">l</span></code> 754 </p> 755 </td> 756<td> 757 <p> 758 <code class="computeroutput"><span class="special">[[:</span><span class="identifier">lower</span><span class="special">:]]</span></code> 759 </p> 760 </td> 761</tr> 762<tr> 763<td> 764 <p> 765 <code class="computeroutput"><span class="special">\</span><span class="identifier">s</span></code> 766 </p> 767 </td> 768<td> 769 <p> 770 <code class="computeroutput"><span class="special">[[:</span><span class="identifier">space</span><span class="special">:]]</span></code> 771 </p> 772 </td> 773</tr> 774<tr> 775<td> 776 <p> 777 <code class="computeroutput"><span class="special">\</span><span class="identifier">u</span></code> 778 </p> 779 </td> 780<td> 781 <p> 782 <code class="computeroutput"><span class="special">[[:</span><span class="identifier">upper</span><span class="special">:]]</span></code> 783 </p> 784 </td> 785</tr> 786<tr> 787<td> 788 <p> 789 <code class="computeroutput"><span class="special">\</span><span class="identifier">w</span></code> 790 </p> 791 </td> 792<td> 793 <p> 794 <code class="computeroutput"><span class="special">[[:</span><span class="identifier">word</span><span class="special">:]]</span></code> 795 </p> 796 </td> 797</tr> 798<tr> 799<td> 800 <p> 801 <code class="computeroutput"><span class="special">\</span><span class="identifier">h</span></code> 802 </p> 803 </td> 804<td> 805 <p> 806 Horizontal whitespace 807 </p> 808 </td> 809</tr> 810<tr> 811<td> 812 <p> 813 <code class="computeroutput"><span class="special">\</span><span class="identifier">v</span></code> 814 </p> 815 </td> 816<td> 817 <p> 818 Vertical whitespace 819 </p> 820 </td> 821</tr> 822<tr> 823<td> 824 <p> 825 <code class="computeroutput"><span class="special">\</span><span class="identifier">D</span></code> 826 </p> 827 </td> 828<td> 829 <p> 830 <code class="computeroutput"><span class="special">[^[:</span><span class="identifier">digit</span><span class="special">:]]</span></code> 831 </p> 832 </td> 833</tr> 834<tr> 835<td> 836 <p> 837 <code class="computeroutput"><span class="special">\</span><span class="identifier">L</span></code> 838 </p> 839 </td> 840<td> 841 <p> 842 <code class="computeroutput"><span class="special">[^[:</span><span class="identifier">lower</span><span class="special">:]]</span></code> 843 </p> 844 </td> 845</tr> 846<tr> 847<td> 848 <p> 849 <code class="computeroutput"><span class="special">\</span><span class="identifier">S</span></code> 850 </p> 851 </td> 852<td> 853 <p> 854 <code class="computeroutput"><span class="special">[^[:</span><span class="identifier">space</span><span class="special">:]]</span></code> 855 </p> 856 </td> 857</tr> 858<tr> 859<td> 860 <p> 861 <code class="computeroutput"><span class="special">\</span><span class="identifier">U</span></code> 862 </p> 863 </td> 864<td> 865 <p> 866 <code class="computeroutput"><span class="special">[^[:</span><span class="identifier">upper</span><span class="special">:]]</span></code> 867 </p> 868 </td> 869</tr> 870<tr> 871<td> 872 <p> 873 <code class="computeroutput"><span class="special">\</span><span class="identifier">W</span></code> 874 </p> 875 </td> 876<td> 877 <p> 878 <code class="computeroutput"><span class="special">[^[:</span><span class="identifier">word</span><span class="special">:]]</span></code> 879 </p> 880 </td> 881</tr> 882<tr> 883<td> 884 <p> 885 <code class="computeroutput"><span class="special">\</span><span class="identifier">H</span></code> 886 </p> 887 </td> 888<td> 889 <p> 890 Not Horizontal whitespace 891 </p> 892 </td> 893</tr> 894<tr> 895<td> 896 <p> 897 <code class="computeroutput"><span class="special">\</span><span class="identifier">V</span></code> 898 </p> 899 </td> 900<td> 901 <p> 902 Not Vertical whitespace 903 </p> 904 </td> 905</tr> 906</tbody> 907</table></div> 908<h6> 909<a name="boost_regex.syntax.perl_syntax.h22"></a> 910 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.character_properties"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.character_properties">Character 911 Properties</a> 912 </h6> 913<p> 914 The character property names in the following table are all equivalent to 915 the <a class="link" href="character_classes.html" title="Character Class Names">names used in character 916 classes</a>. 917 </p> 918<div class="informaltable"><table class="table"> 919<colgroup> 920<col> 921<col> 922<col> 923</colgroup> 924<thead><tr> 925<th> 926 <p> 927 Form 928 </p> 929 </th> 930<th> 931 <p> 932 Description 933 </p> 934 </th> 935<th> 936 <p> 937 Equivalent character set form 938 </p> 939 </th> 940</tr></thead> 941<tbody> 942<tr> 943<td> 944 <p> 945 <code class="computeroutput"><span class="special">\</span><span class="identifier">pX</span></code> 946 </p> 947 </td> 948<td> 949 <p> 950 Matches any character that has the property X. 951 </p> 952 </td> 953<td> 954 <p> 955 <code class="computeroutput"><span class="special">[[:</span><span class="identifier">X</span><span class="special">:]]</span></code> 956 </p> 957 </td> 958</tr> 959<tr> 960<td> 961 <p> 962 <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> 963 </p> 964 </td> 965<td> 966 <p> 967 Matches any character that has the property Name. 968 </p> 969 </td> 970<td> 971 <p> 972 <code class="computeroutput"><span class="special">[[:</span><span class="identifier">Name</span><span class="special">:]]</span></code> 973 </p> 974 </td> 975</tr> 976<tr> 977<td> 978 <p> 979 <code class="computeroutput"><span class="special">\</span><span class="identifier">PX</span></code> 980 </p> 981 </td> 982<td> 983 <p> 984 Matches any character that does not have the property X. 985 </p> 986 </td> 987<td> 988 <p> 989 <code class="computeroutput"><span class="special">[^[:</span><span class="identifier">X</span><span class="special">:]]</span></code> 990 </p> 991 </td> 992</tr> 993<tr> 994<td> 995 <p> 996 <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> 997 </p> 998 </td> 999<td> 1000 <p> 1001 Matches any character that does not have the property Name. 1002 </p> 1003 </td> 1004<td> 1005 <p> 1006 <code class="computeroutput"><span class="special">[^[:</span><span class="identifier">Name</span><span class="special">:]]</span></code> 1007 </p> 1008 </td> 1009</tr> 1010</tbody> 1011</table></div> 1012<p> 1013 For example <code class="literal">\pd</code> matches any "digit" character, 1014 as does <code class="literal">\p{digit}</code>. 1015 </p> 1016<h6> 1017<a name="boost_regex.syntax.perl_syntax.h23"></a> 1018 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.word_boundaries"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.word_boundaries">Word 1019 Boundaries</a> 1020 </h6> 1021<p> 1022 The following escape sequences match the boundaries of words: 1023 </p> 1024<p> 1025 <code class="literal"><</code> Matches the start of a word. 1026 </p> 1027<p> 1028 <code class="literal">></code> Matches the end of a word. 1029 </p> 1030<p> 1031 <code class="literal">\b</code> Matches a word boundary (the start or end of a word). 1032 </p> 1033<p> 1034 <code class="literal">\B</code> Matches only when not at a word boundary. 1035 </p> 1036<h6> 1037<a name="boost_regex.syntax.perl_syntax.h24"></a> 1038 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.buffer_boundaries"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.buffer_boundaries">Buffer 1039 boundaries</a> 1040 </h6> 1041<p> 1042 The following match only at buffer boundaries: a "buffer" in this 1043 context is the whole of the input text that is being matched against (note 1044 that ^ and $ may match embedded newlines within the text). 1045 </p> 1046<p> 1047 \` Matches at the start of a buffer only. 1048 </p> 1049<p> 1050 \' Matches at the end of a buffer only. 1051 </p> 1052<p> 1053 \A Matches at the start of a buffer only (the same as <code class="literal">\`</code>). 1054 </p> 1055<p> 1056 \z Matches at the end of a buffer only (the same as <code class="literal">\'</code>). 1057 </p> 1058<p> 1059 \Z Matches a zero-width assertion consisting of an optional sequence of newlines 1060 at the end of a buffer: equivalent to the regular expression <code class="literal">(?=\v*\z)</code>. 1061 Note that this is subtly different from Perl which behaves as if matching 1062 <code class="literal">(?=\n?\z)</code>. 1063 </p> 1064<h6> 1065<a name="boost_regex.syntax.perl_syntax.h25"></a> 1066 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.continuation_escape"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.continuation_escape">Continuation 1067 Escape</a> 1068 </h6> 1069<p> 1070 The sequence <code class="literal">\G</code> matches only at the end of the last match 1071 found, or at the start of the text being matched if no previous match was 1072 found. This escape useful if you're iterating over the matches contained 1073 within a text, and you want each subsequence match to start where the last 1074 one ended. 1075 </p> 1076<h6> 1077<a name="boost_regex.syntax.perl_syntax.h26"></a> 1078 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.quoting_escape"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.quoting_escape">Quoting 1079 escape</a> 1080 </h6> 1081<p> 1082 The escape sequence <code class="literal">\Q</code> begins a "quoted sequence": 1083 all the subsequent characters are treated as literals, until either the end 1084 of the regular expression or \E is found. For example the expression: <code class="literal">\Q*+\Ea+</code> 1085 would match either of: 1086 </p> 1087<pre class="programlisting"><span class="special">\*+</span><span class="identifier">a</span> 1088<span class="special">\*+</span><span class="identifier">aaa</span> 1089</pre> 1090<h6> 1091<a name="boost_regex.syntax.perl_syntax.h27"></a> 1092 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.unicode_escapes"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.unicode_escapes">Unicode 1093 escapes</a> 1094 </h6> 1095<p> 1096 <code class="literal">\C</code> Matches a single code point: in Boost regex this has 1097 exactly the same effect as a "." operator. <code class="literal">\X</code> 1098 Matches a combining character sequence: that is any non-combining character 1099 followed by a sequence of zero or more combining characters. 1100 </p> 1101<h6> 1102<a name="boost_regex.syntax.perl_syntax.h28"></a> 1103 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.matching_line_endings"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.matching_line_endings">Matching Line 1104 Endings</a> 1105 </h6> 1106<p> 1107 The escape sequence <code class="literal">\R</code> matches any line ending character 1108 sequence, specifically it is identical to the expression <code class="literal">(?>\x0D\x0A?|[\x0A-\x0C\x85\x{2028}\x{2029}])</code>. 1109 </p> 1110<h6> 1111<a name="boost_regex.syntax.perl_syntax.h29"></a> 1112 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.keeping_back_some_text"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.keeping_back_some_text">Keeping back 1113 some text</a> 1114 </h6> 1115<p> 1116 <code class="literal">\K</code> Resets the start location of $0 to the current text 1117 position: in other words everything to the left of \K is "kept back" 1118 and does not form part of the regular expression match. $` is updated accordingly. 1119 </p> 1120<p> 1121 For example <code class="literal">foo\Kbar</code> matched against the text "foobar" 1122 would return the match "bar" for $0 and "foo" for $`. 1123 This can be used to simulate variable width lookbehind assertions. 1124 </p> 1125<h6> 1126<a name="boost_regex.syntax.perl_syntax.h30"></a> 1127 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.any_other_escape"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.any_other_escape">Any 1128 other escape</a> 1129 </h6> 1130<p> 1131 Any other escape sequence matches the character that is escaped, for example 1132 \@ matches a literal '@'. 1133 </p> 1134<h5> 1135<a name="boost_regex.syntax.perl_syntax.h31"></a> 1136 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.perl_extended_patterns"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.perl_extended_patterns">Perl Extended 1137 Patterns</a> 1138 </h5> 1139<p> 1140 Perl-specific extensions to the regular expression syntax all start with 1141 <code class="literal">(?</code>. 1142 </p> 1143<h6> 1144<a name="boost_regex.syntax.perl_syntax.h32"></a> 1145 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.named_subexpressions"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.named_subexpressions">Named 1146 Subexpressions</a> 1147 </h6> 1148<p> 1149 You can create a named subexpression using: 1150 </p> 1151<pre class="programlisting"><span class="special">(?<</span><span class="identifier">NAME</span><span class="special">></span><span class="identifier">expression</span><span class="special">)</span> 1152</pre> 1153<p> 1154 Which can be then be referred to by the name <span class="emphasis"><em>NAME</em></span>. Alternatively 1155 you can delimit the name using 'NAME' as in: 1156 </p> 1157<pre class="programlisting"><span class="special">(?</span><span class="char">'NAME'</span><span class="identifier">expression</span><span class="special">)</span> 1158</pre> 1159<p> 1160 These named subexpressions can be referred to in a backreference using either 1161 <code class="literal">\g{NAME}</code> or <code class="literal">\k<NAME></code> and can 1162 also be referred to by name in a <a class="link" href="../format/perl_format.html" title="Perl Format String Syntax">Perl</a> 1163 format string for search and replace operations, or in the <a class="link" href="../ref/match_results.html" title="match_results"><code class="computeroutput"><span class="identifier">match_results</span></code></a> member functions. 1164 </p> 1165<h6> 1166<a name="boost_regex.syntax.perl_syntax.h33"></a> 1167 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.comments"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.comments">Comments</a> 1168 </h6> 1169<p> 1170 <code class="literal">(?# ... )</code> is treated as a comment, it's contents are ignored. 1171 </p> 1172<h6> 1173<a name="boost_regex.syntax.perl_syntax.h34"></a> 1174 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.modifiers"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.modifiers">Modifiers</a> 1175 </h6> 1176<p> 1177 <code class="literal">(?imsx-imsx ... )</code> alters which of the perl modifiers are 1178 in effect within the pattern, changes take effect from the point that the 1179 block is first seen and extend to any enclosing <code class="literal">)</code>. Letters 1180 before a '-' turn that perl modifier on, letters afterward, turn it off. 1181 </p> 1182<p> 1183 <code class="literal">(?imsx-imsx:pattern)</code> applies the specified modifiers to 1184 pattern only. 1185 </p> 1186<h6> 1187<a name="boost_regex.syntax.perl_syntax.h35"></a> 1188 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.non_marking_groups"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.non_marking_groups">Non-marking 1189 groups</a> 1190 </h6> 1191<p> 1192 <code class="literal">(?:pattern)</code> lexically groups pattern, without generating 1193 an additional sub-expression. 1194 </p> 1195<h6> 1196<a name="boost_regex.syntax.perl_syntax.h36"></a> 1197 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.branch_reset"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.branch_reset">Branch 1198 reset</a> 1199 </h6> 1200<p> 1201 <code class="literal">(?|pattern)</code> resets the subexpression count at the start 1202 of each "|" alternative within <span class="emphasis"><em>pattern</em></span>. 1203 </p> 1204<p> 1205 The sub-expression count following this construct is that of whichever branch 1206 had the largest number of sub-expressions. This construct is useful when 1207 you want to capture one of a number of alternative matches in a single sub-expression 1208 index. 1209 </p> 1210<p> 1211 In the following example the index of each sub-expression is shown below 1212 the expression: 1213 </p> 1214<pre class="programlisting"># before ---------------branch-reset----------- after 1215/ ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x 1216# 1 2 2 3 2 3 4 1217</pre> 1218<h6> 1219<a name="boost_regex.syntax.perl_syntax.h37"></a> 1220 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.lookahead"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.lookahead">Lookahead</a> 1221 </h6> 1222<p> 1223 <code class="literal">(?=pattern)</code> consumes zero characters, only if pattern 1224 matches. 1225 </p> 1226<p> 1227 <code class="literal">(?!pattern)</code> consumes zero characters, only if pattern 1228 does not match. 1229 </p> 1230<p> 1231 Lookahead is typically used to create the logical AND of two regular expressions, 1232 for example if a password must contain a lower case letter, an upper case 1233 letter, a punctuation symbol, and be at least 6 characters long, then the 1234 expression: 1235 </p> 1236<pre class="programlisting"><span class="special">(?=.*[[:</span><span class="identifier">lower</span><span class="special">:]])(?=.*[[:</span><span class="identifier">upper</span><span class="special">:]])(?=.*[[:</span><span class="identifier">punct</span><span class="special">:]]).{</span><span class="number">6</span><span class="special">,}</span> 1237</pre> 1238<p> 1239 could be used to validate the password. 1240 </p> 1241<h6> 1242<a name="boost_regex.syntax.perl_syntax.h38"></a> 1243 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.lookbehind"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.lookbehind">Lookbehind</a> 1244 </h6> 1245<p> 1246 <code class="literal">(?<=pattern)</code> consumes zero characters, only if pattern 1247 could be matched against the characters preceding the current position (pattern 1248 must be of fixed length). 1249 </p> 1250<p> 1251 <code class="literal">(?<!pattern)</code> consumes zero characters, only if pattern 1252 could not be matched against the characters preceding the current position 1253 (pattern must be of fixed length). 1254 </p> 1255<h6> 1256<a name="boost_regex.syntax.perl_syntax.h39"></a> 1257 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.independent_sub_expressions"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.independent_sub_expressions">Independent 1258 sub-expressions</a> 1259 </h6> 1260<p> 1261 <code class="literal">(?>pattern)</code> <span class="emphasis"><em>pattern</em></span> is matched 1262 independently of the surrounding patterns, the expression will never backtrack 1263 into <span class="emphasis"><em>pattern</em></span>. Independent sub-expressions are typically 1264 used to improve performance; only the best possible match for pattern will 1265 be considered, if this doesn't allow the expression as a whole to match then 1266 no match is found at all. 1267 </p> 1268<h6> 1269<a name="boost_regex.syntax.perl_syntax.h40"></a> 1270 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.recursive_expressions"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.recursive_expressions">Recursive 1271 Expressions</a> 1272 </h6> 1273<p> 1274 <code class="literal">(?<span class="emphasis"><em>N</em></span>) (?-<span class="emphasis"><em>N</em></span>) (?+<span class="emphasis"><em>N</em></span>) 1275 (?R) (?0) (?&NAME)</code> 1276 </p> 1277<p> 1278 <code class="literal">(?R)</code> and <code class="literal">(?0)</code> recurse to the start 1279 of the entire pattern. 1280 </p> 1281<p> 1282 <code class="literal">(?<span class="emphasis"><em>N</em></span>)</code> executes sub-expression <span class="emphasis"><em>N</em></span> 1283 recursively, for example <code class="literal">(?2)</code> will recurse to sub-expression 1284 2. 1285 </p> 1286<p> 1287 <code class="literal">(?-<span class="emphasis"><em>N</em></span>)</code> and <code class="literal">(?+<span class="emphasis"><em>N</em></span>)</code> 1288 are relative recursions, so for example <code class="literal">(?-1)</code> recurses 1289 to the last sub-expression to be declared, and <code class="literal">(?+1)</code> recurses 1290 to the next sub-expression to be declared. 1291 </p> 1292<p> 1293 <code class="literal">(?&NAME)</code> recurses to named sub-expression <span class="emphasis"><em>NAME</em></span>. 1294 </p> 1295<h6> 1296<a name="boost_regex.syntax.perl_syntax.h41"></a> 1297 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.conditional_expressions"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.conditional_expressions">Conditional 1298 Expressions</a> 1299 </h6> 1300<p> 1301 <code class="literal">(?(condition)yes-pattern|no-pattern)</code> attempts to match 1302 <span class="emphasis"><em>yes-pattern</em></span> if the <span class="emphasis"><em>condition</em></span> is 1303 true, otherwise attempts to match <span class="emphasis"><em>no-pattern</em></span>. 1304 </p> 1305<p> 1306 <code class="literal">(?(condition)yes-pattern)</code> attempts to match <span class="emphasis"><em>yes-pattern</em></span> 1307 if the <span class="emphasis"><em>condition</em></span> is true, otherwise matches the NULL 1308 string. 1309 </p> 1310<p> 1311 <span class="emphasis"><em>condition</em></span> may be either: a forward lookahead assert, 1312 the index of a marked sub-expression (the condition becomes true if the sub-expression 1313 has been matched), or an index of a recursion (the condition become true 1314 if we are executing directly inside the specified recursion). 1315 </p> 1316<p> 1317 Here is a summary of the possible predicates: 1318 </p> 1319<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 1320<li class="listitem"> 1321 <code class="literal">(?(?=assert)yes-pattern|no-pattern)</code> Executes <span class="emphasis"><em>yes-pattern</em></span> 1322 if the forward look-ahead assert matches, otherwise executes <span class="emphasis"><em>no-pattern</em></span>. 1323 </li> 1324<li class="listitem"> 1325 <code class="literal">(?(?!assert)yes-pattern|no-pattern)</code> Executes <span class="emphasis"><em>yes-pattern</em></span> 1326 if the forward look-ahead assert does not match, otherwise executes 1327 <span class="emphasis"><em>no-pattern</em></span>. 1328 </li> 1329<li class="listitem"> 1330 <code class="literal">(?(<span class="emphasis"><em>N</em></span>)yes-pattern|no-pattern)</code> 1331 Executes <span class="emphasis"><em>yes-pattern</em></span> if subexpression <span class="emphasis"><em>N</em></span> 1332 has been matched, otherwise executes <span class="emphasis"><em>no-pattern</em></span>. 1333 </li> 1334<li class="listitem"> 1335 <code class="literal">(?(<<span class="emphasis"><em>name</em></span>>)yes-pattern|no-pattern)</code> 1336 Executes <span class="emphasis"><em>yes-pattern</em></span> if named subexpression <span class="emphasis"><em>name</em></span> 1337 has been matched, otherwise executes <span class="emphasis"><em>no-pattern</em></span>. 1338 </li> 1339<li class="listitem"> 1340 <code class="literal">(?('<span class="emphasis"><em>name</em></span>')yes-pattern|no-pattern)</code> 1341 Executes <span class="emphasis"><em>yes-pattern</em></span> if named subexpression <span class="emphasis"><em>name</em></span> 1342 has been matched, otherwise executes <span class="emphasis"><em>no-pattern</em></span>. 1343 </li> 1344<li class="listitem"> 1345 <code class="literal">(?(R)yes-pattern|no-pattern)</code> Executes <span class="emphasis"><em>yes-pattern</em></span> 1346 if we are executing inside a recursion, otherwise executes <span class="emphasis"><em>no-pattern</em></span>. 1347 </li> 1348<li class="listitem"> 1349 <code class="literal">(?(R<span class="emphasis"><em>N</em></span>)yes-pattern|no-pattern)</code> 1350 Executes <span class="emphasis"><em>yes-pattern</em></span> if we are executing inside 1351 a recursion to sub-expression <span class="emphasis"><em>N</em></span>, otherwise executes 1352 <span class="emphasis"><em>no-pattern</em></span>. 1353 </li> 1354<li class="listitem"> 1355 <code class="literal">(?(R&<span class="emphasis"><em>name</em></span>)yes-pattern|no-pattern)</code> 1356 Executes <span class="emphasis"><em>yes-pattern</em></span> if we are executing inside 1357 a recursion to named sub-expression <span class="emphasis"><em>name</em></span>, otherwise 1358 executes <span class="emphasis"><em>no-pattern</em></span>. 1359 </li> 1360<li class="listitem"> 1361 <code class="literal">(?(DEFINE)never-exectuted-pattern)</code> Defines a block 1362 of code that is never executed and matches no characters: this is usually 1363 used to define one or more named sub-expressions which are referred to 1364 from elsewhere in the pattern. 1365 </li> 1366</ul></div> 1367<h6> 1368<a name="boost_regex.syntax.perl_syntax.h42"></a> 1369 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.backtracking_control_verbs"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.backtracking_control_verbs">Backtracking 1370 Control Verbs</a> 1371 </h6> 1372<p> 1373 This library has partial support for Perl's backtracking control verbs, in 1374 particular (*MARK) is not supported. There may also be detail differences 1375 in behaviour between this library and Perl, not least because Perl's behaviour 1376 is rather under-documented and often somewhat random in how it behaves in 1377 practice. The verbs supported are: 1378 </p> 1379<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 1380<li class="listitem"> 1381 <code class="literal">(*PRUNE)</code> Has no effect unless backtracked onto, in 1382 which case all the backtracking information prior to this point is discarded. 1383 </li> 1384<li class="listitem"> 1385 <code class="literal">(*SKIP)</code> Behaves the same as <code class="literal">(*PRUNE)</code> 1386 except that it is assumed that no match can possibly occur prior to the 1387 current point in the string being searched. This can be used to optimize 1388 searches by skipping over chunks of text that have already been determined 1389 can not form a match. 1390 </li> 1391<li class="listitem"> 1392 <code class="literal">(*THEN)</code> Has no effect unless backtracked onto, in 1393 which case all subsequent alternatives in a group of alternations are 1394 discarded. 1395 </li> 1396<li class="listitem"> 1397 <code class="literal">(*COMMIT)</code> Has no effect unless backtracked onto, in 1398 which case all subsequent matching/searching attempts are abandoned. 1399 </li> 1400<li class="listitem"> 1401 <code class="literal">(*FAIL)</code> Causes the match to fail unconditionally at 1402 this point, can be used to force the engine to backtrack. 1403 </li> 1404<li class="listitem"> 1405 <code class="literal">(*ACCEPT)</code> Causes the pattern to be considered matched 1406 at the current point. Any half-open sub-expressions are closed at the 1407 current point. 1408 </li> 1409</ul></div> 1410<h5> 1411<a name="boost_regex.syntax.perl_syntax.h43"></a> 1412 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.operator_precedence"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.operator_precedence">Operator 1413 precedence</a> 1414 </h5> 1415<p> 1416 The order of precedence for of operators is as follows: 1417 </p> 1418<div class="orderedlist"><ol class="orderedlist" type="1"> 1419<li class="listitem"> 1420 Collation-related bracket symbols <code class="computeroutput"><span class="special">[==]</span> 1421 <span class="special">[::]</span> <span class="special">[..]</span></code> 1422 </li> 1423<li class="listitem"> 1424 Escaped characters <code class="literal">\</code> 1425 </li> 1426<li class="listitem"> 1427 Character set (bracket expression) <code class="computeroutput"><span class="special">[]</span></code> 1428 </li> 1429<li class="listitem"> 1430 Grouping <code class="literal">()</code> 1431 </li> 1432<li class="listitem"> 1433 Single-character-ERE duplication <code class="literal">* + ? {m,n}</code> 1434 </li> 1435<li class="listitem"> 1436 Concatenation 1437 </li> 1438<li class="listitem"> 1439 Anchoring ^$ 1440 </li> 1441<li class="listitem"> 1442 Alternation | 1443 </li> 1444</ol></div> 1445<h4> 1446<a name="boost_regex.syntax.perl_syntax.h44"></a> 1447 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.what_gets_matched"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.what_gets_matched">What 1448 gets matched</a> 1449 </h4> 1450<p> 1451 If you view the regular expression as a directed (possibly cyclic) graph, 1452 then the best match found is the first match found by a depth-first-search 1453 performed on that graph, while matching the input text. 1454 </p> 1455<p> 1456 Alternatively: 1457 </p> 1458<p> 1459 The best match found is the <a class="link" href="leftmost_longest_rule.html" title="The Leftmost Longest Rule">leftmost 1460 match</a>, with individual elements matched as follows; 1461 </p> 1462<div class="informaltable"><table class="table"> 1463<colgroup> 1464<col> 1465<col> 1466</colgroup> 1467<thead><tr> 1468<th> 1469 <p> 1470 Construct 1471 </p> 1472 </th> 1473<th> 1474 <p> 1475 What gets matched 1476 </p> 1477 </th> 1478</tr></thead> 1479<tbody> 1480<tr> 1481<td> 1482 <p> 1483 <code class="literal">AtomA AtomB</code> 1484 </p> 1485 </td> 1486<td> 1487 <p> 1488 Locates the best match for <span class="emphasis"><em>AtomA</em></span> that has 1489 a following match for <span class="emphasis"><em>AtomB</em></span>. 1490 </p> 1491 </td> 1492</tr> 1493<tr> 1494<td> 1495 <p> 1496 <code class="literal">Expression1 | Expression2</code> 1497 </p> 1498 </td> 1499<td> 1500 <p> 1501 If <span class="emphasis"><em>Expresion1</em></span> can be matched then returns 1502 that match, otherwise attempts to match <span class="emphasis"><em>Expression2</em></span>. 1503 </p> 1504 </td> 1505</tr> 1506<tr> 1507<td> 1508 <p> 1509 <code class="literal">S{N}</code> 1510 </p> 1511 </td> 1512<td> 1513 <p> 1514 Matches <span class="emphasis"><em>S</em></span> repeated exactly N times. 1515 </p> 1516 </td> 1517</tr> 1518<tr> 1519<td> 1520 <p> 1521 <code class="literal">S{N,M}</code> 1522 </p> 1523 </td> 1524<td> 1525 <p> 1526 Matches S repeated between N and M times, and as many times as 1527 possible. 1528 </p> 1529 </td> 1530</tr> 1531<tr> 1532<td> 1533 <p> 1534 <code class="literal">S{N,M}?</code> 1535 </p> 1536 </td> 1537<td> 1538 <p> 1539 Matches S repeated between N and M times, and as few times as possible. 1540 </p> 1541 </td> 1542</tr> 1543<tr> 1544<td> 1545 <p> 1546 <code class="literal">S?, S*, S+</code> 1547 </p> 1548 </td> 1549<td> 1550 <p> 1551 The same as <code class="literal">S{0,1}</code>, <code class="literal">S{0,UINT_MAX}</code>, 1552 <code class="literal">S{1,UINT_MAX}</code> respectively. 1553 </p> 1554 </td> 1555</tr> 1556<tr> 1557<td> 1558 <p> 1559 <code class="literal">S??, S*?, S+?</code> 1560 </p> 1561 </td> 1562<td> 1563 <p> 1564 The same as <code class="literal">S{0,1}?</code>, <code class="literal">S{0,UINT_MAX}?</code>, 1565 <code class="literal">S{1,UINT_MAX}?</code> respectively. 1566 </p> 1567 </td> 1568</tr> 1569<tr> 1570<td> 1571 <p> 1572 <code class="literal">(?>S)</code> 1573 </p> 1574 </td> 1575<td> 1576 <p> 1577 Matches the best match for <span class="emphasis"><em>S</em></span>, and only that. 1578 </p> 1579 </td> 1580</tr> 1581<tr> 1582<td> 1583 <p> 1584 <code class="literal">(?=S), (?<=S)</code> 1585 </p> 1586 </td> 1587<td> 1588 <p> 1589 Matches only the best match for <span class="emphasis"><em>S</em></span> (this is 1590 only visible if there are capturing parenthesis within <span class="emphasis"><em>S</em></span>). 1591 </p> 1592 </td> 1593</tr> 1594<tr> 1595<td> 1596 <p> 1597 <code class="literal">(?!S), (?<!S)</code> 1598 </p> 1599 </td> 1600<td> 1601 <p> 1602 Considers only whether a match for S exists or not. 1603 </p> 1604 </td> 1605</tr> 1606<tr> 1607<td> 1608 <p> 1609 <code class="literal">(?(condition)yes-pattern | no-pattern)</code> 1610 </p> 1611 </td> 1612<td> 1613 <p> 1614 If condition is true, then only yes-pattern is considered, otherwise 1615 only no-pattern is considered. 1616 </p> 1617 </td> 1618</tr> 1619</tbody> 1620</table></div> 1621<h4> 1622<a name="boost_regex.syntax.perl_syntax.h45"></a> 1623 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.variations"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.variations">Variations</a> 1624 </h4> 1625<p> 1626 The <a class="link" href="../ref/syntax_option_type/syntax_option_type_perl.html" title="Options for Perl Regular Expressions">options 1627 <code class="literal">normal</code>, <code class="literal">ECMAScript</code>, <code class="literal">JavaScript</code> 1628 and <code class="literal">JScript</code></a> are all synonyms for <code class="literal">perl</code>. 1629 </p> 1630<h4> 1631<a name="boost_regex.syntax.perl_syntax.h46"></a> 1632 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.options"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.options">Options</a> 1633 </h4> 1634<p> 1635 There are a <a class="link" href="../ref/syntax_option_type/syntax_option_type_perl.html" title="Options for Perl Regular Expressions">variety 1636 of flags</a> that may be combined with the <code class="literal">perl</code> option 1637 when constructing the regular expression, in particular note that the <code class="literal">newline_alt</code> 1638 option alters the syntax, while the <code class="literal">collate</code>, <code class="literal">nosubs</code> 1639 and <code class="literal">icase</code> options modify how the case and locale sensitivity 1640 are to be applied. 1641 </p> 1642<h4> 1643<a name="boost_regex.syntax.perl_syntax.h47"></a> 1644 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.pattern_modifiers"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.pattern_modifiers">Pattern 1645 Modifiers</a> 1646 </h4> 1647<p> 1648 The perl <code class="literal">smix</code> modifiers can either be applied using a 1649 <code class="literal">(?smix-smix)</code> prefix to the regular expression, or with 1650 one of the <a class="link" href="../ref/syntax_option_type/syntax_option_type_perl.html" title="Options for Perl Regular Expressions">regex-compile 1651 time flags <code class="literal">no_mod_m</code>, <code class="literal">mod_x</code>, <code class="literal">mod_s</code>, 1652 and <code class="literal">no_mod_s</code></a>. 1653 </p> 1654<h4> 1655<a name="boost_regex.syntax.perl_syntax.h48"></a> 1656 <span class="phrase"><a name="boost_regex.syntax.perl_syntax.references"></a></span><a class="link" href="perl_syntax.html#boost_regex.syntax.perl_syntax.references">References</a> 1657 </h4> 1658<p> 1659 <a href="http://perldoc.perl.org/perlre.html" target="_top">Perl 5.8</a>. 1660 </p> 1661</div> 1662<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 1663<td align="left"></td> 1664<td align="right"><div class="copyright-footer">Copyright © 1998-2013 John Maddock<p> 1665 Distributed under the Boost Software License, Version 1.0. (See accompanying 1666 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>) 1667 </p> 1668</div></td> 1669</tr></table> 1670<hr> 1671<div class="spirit-nav"> 1672<a accesskey="p" href="../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_extended.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 1673</div> 1674</body> 1675</html> 1676