boost_format_syntax.html 14 KB

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