<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Function regex_replace</title> <link rel="stylesheet" href="../../boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.75.2"> <link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> <link rel="up" href="../../xpressive/reference.html#header.boost.xpressive.regex_algorithms_hpp" title="Header <boost/xpressive/regex_algorithms.hpp>"> <link rel="prev" href="regex_search.html" title="Function regex_search"> <link rel="next" href="regex_compiler.html" title="Struct template regex_compiler"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td> <td align="center"><a href="../../../../index.html">Home</a></td> <td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="regex_search.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../xpressive/reference.html#header.boost.xpressive.regex_algorithms_hpp"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="regex_compiler.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a> </div> <div class="refentry" title="Function regex_replace"> <a name="boost.xpressive.regex_replace"></a><div class="titlepage"></div> <div class="refnamediv"> <h2><span class="refentrytitle">Function regex_replace</span></h2> <p>boost::xpressive::regex_replace — Build an output sequence given an input sequence, a regex, and a format string or a formatter object, function, or expression. </p> </div> <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="emphasis"><em>// In header: <<a class="link" href="../../xpressive/reference.html#header.boost.xpressive.regex_algorithms_hpp" title="Header <boost/xpressive/regex_algorithms.hpp>">boost/xpressive/regex_algorithms.hpp</a>> </em></span> <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> OutIter, <span class="bold"><strong>typename</strong></span> BidiIter, <span class="bold"><strong>typename</strong></span> Formatter> <span class="type">OutIter</span> regex_replace(OutIter out, BidiIter begin, BidiIter end, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< BidiIter > <span class="bold"><strong>const</strong></span> & re, Formatter <span class="bold"><strong>const</strong></span> & format, regex_constants::match_flag_type flags = regex_constants::match_default, <span class="emphasis"><em>unspecified</em></span> = 0); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> OutIter, <span class="bold"><strong>typename</strong></span> BidiIter> <span class="type">OutIter</span> regex_replace(OutIter out, BidiIter begin, BidiIter end, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< BidiIter > <span class="bold"><strong>const</strong></span> & re, <span class="bold"><strong>typename</strong></span> iterator_value< BidiIter >::type <span class="bold"><strong>const</strong></span> * format, regex_constants::match_flag_type flags = regex_constants::match_default); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> BidiContainer, <span class="bold"><strong>typename</strong></span> BidiIter, <span class="bold"><strong>typename</strong></span> Formatter> <span class="type">BidiContainer</span> regex_replace(BidiContainer & str, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< BidiIter > <span class="bold"><strong>const</strong></span> & re, Formatter <span class="bold"><strong>const</strong></span> & format, regex_constants::match_flag_type flags = regex_constants::match_default, <span class="emphasis"><em>unspecified</em></span> = 0); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> BidiContainer, <span class="bold"><strong>typename</strong></span> BidiIter, <span class="bold"><strong>typename</strong></span> Formatter> <span class="type">BidiContainer</span> regex_replace(BidiContainer <span class="bold"><strong>const</strong></span> & str, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< BidiIter > <span class="bold"><strong>const</strong></span> & re, Formatter <span class="bold"><strong>const</strong></span> & format, regex_constants::match_flag_type flags = regex_constants::match_default, <span class="emphasis"><em>unspecified</em></span> = 0); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Char, <span class="bold"><strong>typename</strong></span> Formatter> <span class="type">std::basic_string< <span class="bold"><strong>typename</strong></span> remove_const< Char >::type ></span> regex_replace(Char * str, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< Char * > <span class="bold"><strong>const</strong></span> & re, Formatter <span class="bold"><strong>const</strong></span> & format, regex_constants::match_flag_type flags = regex_constants::match_default, <span class="emphasis"><em>unspecified</em></span> = 0); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> BidiContainer, <span class="bold"><strong>typename</strong></span> BidiIter> <span class="type">BidiContainer</span> regex_replace(BidiContainer & str, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< BidiIter > <span class="bold"><strong>const</strong></span> & re, <span class="bold"><strong>typename</strong></span> iterator_value< BidiIter >::type <span class="bold"><strong>const</strong></span> * format, regex_constants::match_flag_type flags = regex_constants::match_default, <span class="emphasis"><em>unspecified</em></span> = 0); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> BidiContainer, <span class="bold"><strong>typename</strong></span> BidiIter> <span class="type">BidiContainer</span> regex_replace(BidiContainer <span class="bold"><strong>const</strong></span> & str, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< BidiIter > <span class="bold"><strong>const</strong></span> & re, <span class="bold"><strong>typename</strong></span> iterator_value< BidiIter >::type <span class="bold"><strong>const</strong></span> * format, regex_constants::match_flag_type flags = regex_constants::match_default, <span class="emphasis"><em>unspecified</em></span> = 0); <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Char> <span class="type">std::basic_string< <span class="bold"><strong>typename</strong></span> remove_const< Char >::type ></span> regex_replace(Char * str, <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a>< Char * > <span class="bold"><strong>const</strong></span> & re, <span class="bold"><strong>typename</strong></span> add_const< Char >::type * format, regex_constants::match_flag_type flags = regex_constants::match_default);</pre></div> <div class="refsect1" title="Description"> <a name="id2116943"></a><h2>Description</h2> <p>Constructs a <code class="computeroutput">regex_iterator</code> object: <code class="computeroutput">regex_iterator< BidiIter > i(begin, end, re, flags)</code>, and uses <code class="computeroutput">i</code> to enumerate through all of the matches m of type <code class="computeroutput">match_results< BidiIter ></code> that occur within the sequence <code class="computeroutput">[begin, end)</code>. If no such matches are found and <code class="computeroutput">!(flags & format_no_copy)</code> then calls <code class="computeroutput">std::copy(begin, end, out)</code>. Otherwise, for each match found, if <code class="computeroutput">!(flags & format_no_copy)</code> calls <code class="computeroutput">std::copy(m.prefix().first, m.prefix().second, out)</code>, and then calls <code class="computeroutput">m.format(out, format, flags)</code>. Finally if <code class="computeroutput">!(flags & format_no_copy)</code> calls <code class="computeroutput">std::copy(last_m.suffix().first, last_m.suffix().second, out)</code> where <code class="computeroutput">last_m</code> is a copy of the last match found.</p> <p>If <code class="computeroutput">flags & format_first_only</code> is non-zero then only the first match found is replaced.</p> <p> </p> <div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term">Parameters:</span></p></td> <td><div class="variablelist"><table border="0"> <col align="left" valign="top"> <tbody> <tr> <td><p><span class="term"><code class="computeroutput">begin</code></span></p></td> <td><p>The beginning of the input sequence. </p></td> </tr> <tr> <td><p><span class="term"><code class="computeroutput">end</code></span></p></td> <td><p>The end of the input sequence. </p></td> </tr> <tr> <td><p><span class="term"><code class="computeroutput">flags</code></span></p></td> <td><p>Optional match flags, used to control how the expression is matched against the sequence. (See <code class="computeroutput">match_flag_type</code>.) </p></td> </tr> <tr> <td><p><span class="term"><code class="computeroutput">format</code></span></p></td> <td><p>The format string used to format the replacement sequence, or a formatter function, function object, or expression. </p></td> </tr> <tr> <td><p><span class="term"><code class="computeroutput">out</code></span></p></td> <td><p>An output iterator into which the output sequence is written. </p></td> </tr> <tr> <td><p><span class="term"><code class="computeroutput">re</code></span></p></td> <td><p>The regular expression object to use. </p></td> </tr> </tbody> </table></div></td> </tr> <tr> <td><p><span class="term">Requires:</span></p></td> <td> <p>Type <code class="computeroutput">BidiIter</code> meets the requirements of a Bidirectional Iterator (24.1.4). </p> <p>Type <code class="computeroutput">OutIter</code> meets the requirements of an Output Iterator (24.1.2). </p> <p>Type <code class="computeroutput">Formatter</code> models <code class="computeroutput">ForwardRange</code>, <code class="computeroutput">Callable<match_results<BidiIter> ></code>, <code class="computeroutput">Callable<match_results<BidiIter>, OutIter></code>, or <code class="computeroutput">Callable<match_results<BidiIter>, OutIter, regex_constants::match_flag_type></code>; or else it is a null-terminated format string, or an expression template representing a formatter lambda expression. </p> <p><code class="computeroutput">[begin,end)</code> denotes a valid iterator range. </p> </td> </tr> <tr> <td><p><span class="term">Returns:</span></p></td> <td><p>The value of the output iterator after the output sequence has been written to it. </p></td> </tr> <tr> <td><p><span class="term">Throws:</span></p></td> <td> <a class="link" href="regex_error.html" title="Struct regex_error">regex_error</a> </td> </tr> </tbody> </table></div> </div> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2007 Eric Niebler<p> Distributed under the Boost Software License, Version 1.0. (See accompanying 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>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="regex_search.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../xpressive/reference.html#header.boost.xpressive.regex_algorithms_hpp"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="regex_compiler.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a> </div> </body> </html>