File: format_syntax.html

package info (click to toggle)
boost 1.32.0-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 93,952 kB
  • ctags: 128,458
  • sloc: cpp: 492,477; xml: 52,125; python: 13,519; ansic: 13,013; sh: 1,773; yacc: 853; makefile: 526; perl: 418; lex: 110; csh: 6
file content (263 lines) | stat: -rw-r--r-- 7,390 bytes parent folder | download
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<title>Boost.Regex: Format String Syntax</title>
<meta http-equiv="Content-Type" content=
"text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../../boost.css">
</head>
<body>
<p></p>

<table id="Table1" cellspacing="1" cellpadding="1" width="100%"
border="0">
<tr>
<td valign="top" width="300">
<h3><a href="../../../index.htm"><img height="86" width="277" alt=
"C++ Boost" src="../../../boost.png" border="0"></a></h3>
</td>
<td width="353">
<h1 align="center">Boost.Regex</h1>

<h2 align="center">Format String Syntax</h2>
</td>
<td width="50">
<h3><a href="index.html"><img height="45" width="43" alt=
"Boost.Regex Index" src="uarrow.gif" border="0"></a></h3>
</td>
</tr>
</table>

<br>
<br>
 

<hr>
<p>Format strings are used by the algorithm <a href="regex_replace.html">regex_replace</a>&nbsp;and by <a
href="match_results.html">match_results::format</a>, and are used
to transform one string into another.</p>

<p>There are three kind of format string: sed, Perl and extended,
the extended syntax is a superset of the others so this is covered
first.</p>

<p><b><i>Extended format syntax</i></b></p>

<p>In format strings, all characters are treated as literals
except: ()$\?:</p>

<p>To use any of these as literals you must prefix them with the
escape character \</p>

<p>The following special sequences are recognized:&nbsp;<br>
 &nbsp;<br>
 <i>Grouping:</i></p>

<p>Use the parenthesis characters ( and ) to group sub-expressions
within the format string, use \( and \) to represent literal '('
and ')'.&nbsp;<br>
 &nbsp;<br>
 <i>Sub-expression expansions:</i></p>

<p>The following Perl like expressions expand to a particular
matched sub-expression:<br>
 &nbsp;</p>

<p></p>

<table id="Table2" cellspacing="0" cellpadding="7" width="100%"
border="0">
<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">$`</td>
<td valign="top" width="43%">Expands to all the text from the end
of the previous match to the start of the current match, if there
was no previous match in the current operation, then everything
from the start of the input string to the start of the match.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">$'</td>
<td valign="top" width="43%">Expands to all the text from the end
of the match to the end of the input string.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">$&amp;</td>
<td valign="top" width="43%">Expands to all of the current
match.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">$0</td>
<td valign="top" width="43%">Expands to all of the current
match.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">$N</td>
<td valign="top" width="43%">Expands to the text that matched
sub-expression <i>N</i>.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>
</table>

<br>
<br>
 

<p><i>Conditional expressions:</i></p>

<p>Conditional expressions allow two different format strings to be
selected dependent upon whether a sub-expression participated in
the match or not:</p>

<p>?Ntrue_expression:false_expression</p>

<p>Executes true_expression if sub-expression <i>N</i> participated
in the match, otherwise executes false_expression.</p>

<p>Example: suppose we search for "(while)|(for)" then the format
string "?1WHILE:FOR" would output what matched, but in upper
case.&nbsp;<br>
 &nbsp;<br>
 <i>Escape sequences:</i></p>

<p>The following escape sequences are also allowed:<br>
</p>

<p></p>

<table id="Table3" cellspacing="0" cellpadding="7" width="100%"
border="0">
<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\a</td>
<td valign="top" width="43%">The bell character.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\f</td>
<td valign="top" width="43%">The form feed character.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\n</td>
<td valign="top" width="43%">The newline character.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\r</td>
<td valign="top" width="43%">The carriage return character.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\t</td>
<td valign="top" width="43%">The tab character.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\v</td>
<td valign="top" width="43%">A vertical tab character.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\x</td>
<td valign="top" width="43%">A hexadecimal character - for example
\x0D.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\x{}</td>
<td valign="top" width="43%">A possible Unicode hexadecimal
character - for example \x{1A0}</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\cx</td>
<td valign="top" width="43%">The ASCII escape character x, for
example \c@ is equivalent to escape-@.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\e</td>
<td valign="top" width="43%">The ASCII escape character.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>

<tr>
<td valign="top" width="8%">&nbsp;</td>
<td valign="top" width="40%">\dd</td>
<td valign="top" width="43%">An octal character constant, for
example \10.</td>
<td valign="top" width="9%">&nbsp;</td>
</tr>
</table>

<br>
<br>
 

<p><b><i>Perl format strings</i></b></p>

<p>Perl format strings are the same as the default syntax except
that the characters ()?: have no special meaning.</p>

<p><b><i>Sed format strings</i></b></p>

<p>Sed format strings use only the characters \ and &amp; as
special characters.</p>

<p>\n where n is a digit, is expanded to the nth
sub-expression.</p>

<p>&amp; is expanded to the whole of the match (equivalent to
\0).</p>

<p>Other escape sequences are expanded as per the default
syntax.</p>

<p></p>

<hr>
      <p>Revised 
         <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> 
         24 Oct 2003 
         <!--webbot bot="Timestamp" endspan i-checksum="39359" --></p>
      <p><i> Copyright John Maddock&nbsp;1998- 
            <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y" startspan --> 
            2003<!--webbot bot="Timestamp" endspan i-checksum="39359" --></i></p>
      <P><I>Use, modification and distribution are subject to the Boost Software License, 
            Version 1.0. (See accompanying file <A href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</A>
            or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>)</I></P>
</body>
</html>