1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Perl Format String 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="../format.html" title="Search and Replace Format String Syntax"> 9<link rel="prev" href="sed_format.html" title="Sed Format String Syntax"> 10<link rel="next" href="boost_format_syntax.html" title="Boost-Extended Format String 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="sed_format.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../format.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="boost_format_syntax.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.format.perl_format"></a><a class="link" href="perl_format.html" title="Perl Format String Syntax">Perl Format String Syntax</a> 28</h3></div></div></div> 29<p> 30 Perl-style format strings treat all characters as literals except '$' and 31 '\' which start placeholder and escape sequences respectively. 32 </p> 33<p> 34 Placeholder sequences specify that some part of what matched the regular 35 expression should be sent to output as follows: 36 </p> 37<div class="informaltable"><table class="table"> 38<colgroup> 39<col> 40<col> 41</colgroup> 42<thead><tr> 43<th> 44 <p> 45 Placeholder 46 </p> 47 </th> 48<th> 49 <p> 50 Meaning 51 </p> 52 </th> 53</tr></thead> 54<tbody> 55<tr> 56<td> 57 <p> 58 $& 59 </p> 60 </td> 61<td> 62 <p> 63 Outputs what matched the whole expression. 64 </p> 65 </td> 66</tr> 67<tr> 68<td> 69 <p> 70 $MATCH 71 </p> 72 </td> 73<td> 74 <p> 75 As $& 76 </p> 77 </td> 78</tr> 79<tr> 80<td> 81 <p> 82 ${^MATCH} 83 </p> 84 </td> 85<td> 86 <p> 87 As $& 88 </p> 89 </td> 90</tr> 91<tr> 92<td> 93 <p> 94 $` 95 </p> 96 </td> 97<td> 98 <p> 99 Outputs the text between the end of the last match found (or the 100 start of the text if no previous match was found), and the start 101 of the current match. 102 </p> 103 </td> 104</tr> 105<tr> 106<td> 107 <p> 108 $PREMATCH 109 </p> 110 </td> 111<td> 112 <p> 113 As $` 114 </p> 115 </td> 116</tr> 117<tr> 118<td> 119 <p> 120 ${^PREMATCH} 121 </p> 122 </td> 123<td> 124 <p> 125 As $` 126 </p> 127 </td> 128</tr> 129<tr> 130<td> 131 <p> 132 $' 133 </p> 134 </td> 135<td> 136 <p> 137 Outputs all the text following the end of the current match. 138 </p> 139 </td> 140</tr> 141<tr> 142<td> 143 <p> 144 $POSTMATCH 145 </p> 146 </td> 147<td> 148 <p> 149 As $' 150 </p> 151 </td> 152</tr> 153<tr> 154<td> 155 <p> 156 ${^POSTMATCH} 157 </p> 158 </td> 159<td> 160 <p> 161 As $' 162 </p> 163 </td> 164</tr> 165<tr> 166<td> 167 <p> 168 $+ 169 </p> 170 </td> 171<td> 172 <p> 173 Outputs what matched the last marked sub-expression in the regular 174 expression. 175 </p> 176 </td> 177</tr> 178<tr> 179<td> 180 <p> 181 $LAST_PAREN_MATCH 182 </p> 183 </td> 184<td> 185 <p> 186 As $+ 187 </p> 188 </td> 189</tr> 190<tr> 191<td> 192 <p> 193 $LAST_SUBMATCH_RESULT 194 </p> 195 </td> 196<td> 197 <p> 198 Outputs what matched the last sub-expression to be actually matched. 199 </p> 200 </td> 201</tr> 202<tr> 203<td> 204 <p> 205 $^N 206 </p> 207 </td> 208<td> 209 <p> 210 As $LAST_SUBMATCH_RESULT 211 </p> 212 </td> 213</tr> 214<tr> 215<td> 216 <p> 217 $$ 218 </p> 219 </td> 220<td> 221 <p> 222 Outputs a literal '$' 223 </p> 224 </td> 225</tr> 226<tr> 227<td> 228 <p> 229 $n 230 </p> 231 </td> 232<td> 233 <p> 234 Outputs what matched the n'th sub-expression. 235 </p> 236 </td> 237</tr> 238<tr> 239<td> 240 <p> 241 ${n} 242 </p> 243 </td> 244<td> 245 <p> 246 Outputs what matched the n'th sub-expression. 247 </p> 248 </td> 249</tr> 250<tr> 251<td> 252 <p> 253 $+{NAME} 254 </p> 255 </td> 256<td> 257 <p> 258 Outputs whatever matched the sub-expression named "NAME". 259 </p> 260 </td> 261</tr> 262</tbody> 263</table></div> 264<p> 265 Any $-placeholder sequence not listed above, results in '$' being treated 266 as a literal. 267 </p> 268<p> 269 An escape character followed by any character x, outputs that character unless 270 x is one of the escape sequences shown below. 271 </p> 272<div class="informaltable"><table class="table"> 273<colgroup> 274<col> 275<col> 276</colgroup> 277<thead><tr> 278<th> 279 <p> 280 Escape 281 </p> 282 </th> 283<th> 284 <p> 285 Meaning 286 </p> 287 </th> 288</tr></thead> 289<tbody> 290<tr> 291<td> 292 <p> 293 \a 294 </p> 295 </td> 296<td> 297 <p> 298 Outputs the bell character: '\a'. 299 </p> 300 </td> 301</tr> 302<tr> 303<td> 304 <p> 305 \e 306 </p> 307 </td> 308<td> 309 <p> 310 Outputs the ANSI escape character (code point 27). 311 </p> 312 </td> 313</tr> 314<tr> 315<td> 316 <p> 317 \f 318 </p> 319 </td> 320<td> 321 <p> 322 Outputs a form feed character: '\f' 323 </p> 324 </td> 325</tr> 326<tr> 327<td> 328 <p> 329 \n 330 </p> 331 </td> 332<td> 333 <p> 334 Outputs a newline character: '\n'. 335 </p> 336 </td> 337</tr> 338<tr> 339<td> 340 <p> 341 \r 342 </p> 343 </td> 344<td> 345 <p> 346 Outputs a carriage return character: '\r'. 347 </p> 348 </td> 349</tr> 350<tr> 351<td> 352 <p> 353 \t 354 </p> 355 </td> 356<td> 357 <p> 358 Outputs a tab character: '\t'. 359 </p> 360 </td> 361</tr> 362<tr> 363<td> 364 <p> 365 \v 366 </p> 367 </td> 368<td> 369 <p> 370 Outputs a vertical tab character: '\v'. 371 </p> 372 </td> 373</tr> 374<tr> 375<td> 376 <p> 377 \xDD 378 </p> 379 </td> 380<td> 381 <p> 382 Outputs the character whose hexadecimal code point is 0xDD 383 </p> 384 </td> 385</tr> 386<tr> 387<td> 388 <p> 389 \x{DDDD} 390 </p> 391 </td> 392<td> 393 <p> 394 Outputs the character whose hexadecimal code point is 0xDDDDD 395 </p> 396 </td> 397</tr> 398<tr> 399<td> 400 <p> 401 \cX 402 </p> 403 </td> 404<td> 405 <p> 406 Outputs the ANSI escape sequence "escape-X". 407 </p> 408 </td> 409</tr> 410<tr> 411<td> 412 <p> 413 \D 414 </p> 415 </td> 416<td> 417 <p> 418 If D is a decimal digit in the range 1-9, then outputs the text 419 that matched sub-expression D. 420 </p> 421 </td> 422</tr> 423<tr> 424<td> 425 <p> 426 \l 427 </p> 428 </td> 429<td> 430 <p> 431 Causes the next character to be outputted, to be output in lower 432 case. 433 </p> 434 </td> 435</tr> 436<tr> 437<td> 438 <p> 439 \u 440 </p> 441 </td> 442<td> 443 <p> 444 Causes the next character to be outputted, to be output in upper 445 case. 446 </p> 447 </td> 448</tr> 449<tr> 450<td> 451 <p> 452 \L 453 </p> 454 </td> 455<td> 456 <p> 457 Causes all subsequent characters to be output in lower case, until 458 a \E is found. 459 </p> 460 </td> 461</tr> 462<tr> 463<td> 464 <p> 465 \U 466 </p> 467 </td> 468<td> 469 <p> 470 Causes all subsequent characters to be output in upper case, until 471 a \E is found. 472 </p> 473 </td> 474</tr> 475<tr> 476<td> 477 <p> 478 \E 479 </p> 480 </td> 481<td> 482 <p> 483 Terminates a \L or \U sequence. 484 </p> 485 </td> 486</tr> 487</tbody> 488</table></div> 489</div> 490<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 491<td align="left"></td> 492<td align="right"><div class="copyright-footer">Copyright © 1998-2013 John Maddock<p> 493 Distributed under the Boost Software License, Version 1.0. (See accompanying 494 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>) 495 </p> 496</div></td> 497</tr></table> 498<hr> 499<div class="spirit-nav"> 500<a accesskey="p" href="sed_format.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../format.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="boost_format_syntax.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 501</div> 502</body> 503</html> 504