Files
boost_regex/doc/format_syntax.html
T
John Maddock c8f2ed3bdb Added new docs,
Moved source more into line with the std lib proposal.


[SVN r18292]
2003-04-23 10:49:57 +00:00

218 lines
9.6 KiB
HTML

<!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>&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>
<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>
</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.&nbsp;<BR>
&nbsp;
<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%">&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>
</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 &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>
<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>&nbsp;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>