forked from boostorg/regex
Finished checking docs, code should now be ready for release...
[SVN r18428]
This commit is contained in:
+269
-214
@@ -1,217 +1,272 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<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>
|
||||
<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="../../../c++boost.gif" 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>
|
||||
</P>
|
||||
<HR>
|
||||
<p></p>
|
||||
<P>Format strings are used by the algorithm <A href="template_class_ref.htm#reg_merge">
|
||||
regex_merge</A> 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: <BR>
|
||||
|
||||
<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 ')'. <BR>
|
||||
|
||||
<BR>
|
||||
<I>Sub-expression expansions:</I>
|
||||
</P>
|
||||
<P>The following Perl like expressions expand to a particular matched
|
||||
sub-expression:
|
||||
<BR>
|
||||
|
||||
</P>
|
||||
<P>
|
||||
<TABLE id="Table2" cellSpacing="0" cellPadding="7" width="100%" border="0">
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">$&</TD>
|
||||
<TD vAlign="top" width="43%">Expands to all of the current match.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</P>
|
||||
<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. <BR>
|
||||
|
||||
<BR>
|
||||
<I>Escape sequences:</I>
|
||||
</P>
|
||||
<P>The following escape sequences are also allowed:
|
||||
<BR>
|
||||
</P>
|
||||
<P>
|
||||
<TABLE id="Table3" cellSpacing="0" cellPadding="7" width="100%" border="0">
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">\a</TD>
|
||||
<TD vAlign="top" width="43%">The bell character.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">\f</TD>
|
||||
<TD vAlign="top" width="43%">The form feed character.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">\n</TD>
|
||||
<TD vAlign="top" width="43%">The newline character.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">\r</TD>
|
||||
<TD vAlign="top" width="43%">The carriage return character.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">\t</TD>
|
||||
<TD vAlign="top" width="43%">The tab character.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">\v</TD>
|
||||
<TD vAlign="top" width="43%">A vertical tab character.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </TD>
|
||||
<TD vAlign="top" width="40%">\e</TD>
|
||||
<TD vAlign="top" width="43%">The ASCII escape character.</TD>
|
||||
<TD vAlign="top" width="9%"> </TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD vAlign="top" width="8%"> </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%"> </TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</P>
|
||||
<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 & as special characters.
|
||||
</P>
|
||||
<P>\n where n is a digit, is expanded to the nth sub-expression.
|
||||
</P>
|
||||
<P>& is expanded to the whole of the match (equivalent to \0).
|
||||
</P>
|
||||
<P>
|
||||
Other escape sequences are expanded as per the default syntax.
|
||||
<P>
|
||||
<HR>
|
||||
<P></P>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
11 April 2003
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
<P><I>© Copyright <a href="mailto:jm@regex.fsnet.co.uk">John Maddock</a> 1998-<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y" startspan --> 2003<!--webbot bot="Timestamp" endspan i-checksum="39359" --></I></P>
|
||||
<P align="left"><I>Permission to use, copy, modify, distribute and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee, provided
|
||||
that the above copyright notice appear in all copies and that both that
|
||||
copyright notice and this permission notice appear in supporting documentation.
|
||||
Dr John Maddock makes no representations about the suitability of this software
|
||||
for any purpose. It is provided "as is" without express or implied warranty.</I></P>
|
||||
</body>
|
||||
<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="../../../c++boost.gif" 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="template_class_ref.htm#reg_merge">regex_merge</a> 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: <br>
|
||||
<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 ')'. <br>
|
||||
<br>
|
||||
<i>Sub-expression expansions:</i></p>
|
||||
|
||||
<p>The following Perl like expressions expand to a particular
|
||||
matched sub-expression:<br>
|
||||
</p>
|
||||
|
||||
<p></p>
|
||||
|
||||
<table id="Table2" cellspacing="0" cellpadding="7" width="100%"
|
||||
border="0">
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </td>
|
||||
<td valign="top" width="40%">$&</td>
|
||||
<td valign="top" width="43%">Expands to all of the current
|
||||
match.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </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. <br>
|
||||
<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%"> </td>
|
||||
<td valign="top" width="40%">\a</td>
|
||||
<td valign="top" width="43%">The bell character.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </td>
|
||||
<td valign="top" width="40%">\f</td>
|
||||
<td valign="top" width="43%">The form feed character.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </td>
|
||||
<td valign="top" width="40%">\n</td>
|
||||
<td valign="top" width="43%">The newline character.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </td>
|
||||
<td valign="top" width="40%">\r</td>
|
||||
<td valign="top" width="43%">The carriage return character.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </td>
|
||||
<td valign="top" width="40%">\t</td>
|
||||
<td valign="top" width="43%">The tab character.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </td>
|
||||
<td valign="top" width="40%">\v</td>
|
||||
<td valign="top" width="43%">A vertical tab character.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </td>
|
||||
<td valign="top" width="40%">\e</td>
|
||||
<td valign="top" width="43%">The ASCII escape character.</td>
|
||||
<td valign="top" width="9%"> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top" width="8%"> </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%"> </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 & as
|
||||
special characters.</p>
|
||||
|
||||
<p>\n where n is a digit, is expanded to the nth
|
||||
sub-expression.</p>
|
||||
|
||||
<p>& 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 -->
|
||||
17 May 2003
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" --></p>
|
||||
|
||||
<p><i>© Copyright <a href="mailto:jm@regex.fsnet.co.uk">John
|
||||
Maddock</a> 1998-
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y" startspan -->
|
||||
2003
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" --></i></p>
|
||||
|
||||
<p align="left"><i>Permission to use, copy, modify, distribute and
|
||||
sell this software and its documentation for any purpose is hereby
|
||||
granted without fee, provided that the above copyright notice
|
||||
appear in all copies and that both that copyright notice and this
|
||||
permission notice appear in supporting documentation. Dr John
|
||||
Maddock makes no representations about the suitability of this
|
||||
software for any purpose. It is provided "as is" without express or
|
||||
implied warranty.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user