Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Function regex_replace

boost::xpressive::regex_replace — Build an output sequence given an input sequence, a regex, and a format string.


template<typename OutIter, typename OtherBidiIter, typename BidiIter> 
OutIter regex_replace(OutIter out, OtherBidiIter begin, OtherBidiIter end, 
basic_regex< BidiIter > const & re, 
std::basic_string< typename iterator_value< BidiIter >::type > const & fmt, 
regex_constants::match_flag_type flags = regex_constants::match_default);
template<typename Char> 
std::basic_string< Char > 
regex_replace(std::basic_string< Char > const & str, 
basic_regex< typename std::basic_string< Char >::const_iterator > const & re, 
std::basic_string< Char > const & fmt, 
regex_constants::match_flag_type flags = regex_constants::match_default);


Constructs a regex_iterator object: regex_iterator< BidiIter > i(begin, end, re, flags), and uses i to enumerate through all of the matches m of type match_results< BidiIter > that occur within the sequence [begin, end). If no such matches are found and !(flags & format_no_copy) then calls std::copy(begin, end, out). Otherwise, for each match found, if !(flags & format_no_copy) calls std::copy(m.prefix().first, m.prefix().second, out), and then calls m.format(out, fmt, flags). Finally if !(flags & format_no_copy) calls std::copy(last_m.suffix().first, last_m.suffix().second, out) where last_m is a copy of the last match found. If flags & format_first_only is non-zero then only the first match found is replaced.


The beginning of the input sequence.


The end of the input sequence.


Optional match flags, used to control how the expression is matched against the sequence. (See match_flag_type.)


The format string used to format the replacement sequence.


An output iterator into which the output sequence is written.


The regular expression object to use.


Types BidiIter and OtherBidiIter meet the requirements of a Bidirectional Iterator (24.1.4).

Type OutIter meets the requirements of an Output Iterator (24.1.2).

OtherBidiIter is convertible to BidiIter.

[begin,end) denotes a valid iterator range.


The value of the output iterator after the output sequence has been written to it.

Throws: regex_error on stack exhaustion or invalid format string.
Copyright 2003, 2004 Eric Niebler