std::regex_replace

From Cppreference

Jump to: navigation, search
Defined in header <regex>

template< class OutputIterator, class BidirectionalIterator,

          class Traits, class CharT,
          class STraits, class SAlloc >
OutputIterator
    regex_replace( OutputIterator out,
                   BidirectionalIterator first, BidirectionalIterator last,
                   const std::basic_regex<CharT,Traits>& e,
                   const std::basic_string<CharT,STraits,SAlloc>& fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default );
(1) (C++11 feature)
template< class OutputIterator, class BidirectionalIterator,

          class Traits, class CharT >
OutputIterator
    regex_replace( OutputIterator out,
                   BidirectionalIterator first, BidirectionalIterator last,
                   const std::basic_regex<CharT,Traits>& e,
                   const CharT* fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default );
(2) (C++11 feature)
template< class Traits, class CharT,

          class STraits, class SAlloc,
          class FTraits, class FAlloc >
std::basic_string<CharT,STraits,SAlloc>
    regex_replace( const std::basic_string<CharT,STraits,SAlloc>& s,
                   const std::basic_regex<CharT,Traits>& e,
                   const std::basic_string<CharT,FTraits,FAlloc>& fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default );
(3) (C++11 feature)
template< class Traits, class CharT,

          class STraits, class SAlloc >
std::basic_string<CharT,STraits,SAlloc>
    regex_replace( const std::basic_string<CharT,STraits,SAlloc>& s,
                   const std::basic_regex<CharT,Traits>& e,
                   const CharT* fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default );
(4) (C++11 feature)
template< class Traits, class CharT,

          class STraits, class SAlloc >
std::basic_string<CharT>
    regex_replace( const CharT* s,
                   const std::basic_regex<CharT,Traits>& e,
                   const std::basic_string<CharT,STraits,SAlloc>& fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default );
(5) (C++11 feature)
template< class Traits, class CharT >

std::basic_string<CharT>
    regex_replace( const CharT* s,
                   const std::basic_regex<CharT,Traits>& e,
                   const CharT*fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default );
(6) (C++11 feature)

1) Constructs a std::regex_iterator object i as if by std::regex_iterator<BidirectionalIterator, CharT, traits> i(first, last, e, flags), and uses i to enumerate through all of the matches m of type std::match_results<BidirectionalIterator> that occur within the sequence [first,last ).

2) Same as (1).

3) Constructs an empty string result of type std::basic_string<CharT, ST, SA> and calls std::regex_replace(std::back_inserter(result), s.begin(), s.end(), e, fmt, flags).

4) Same as (3).

5) Constructs an empty string result of type std::basic_string<CharT> and calls std::regex_replace(std::back_inserter(result), s, s + std::char_traits<CharT>::length(s), e, fmt, flags).

6) Same as (5).

[edit] Parameters

out - an output iterator with the result
first, last - the target character range
m - the match results
fmt - a regex replacement format string
s - a target character std::basic_string
e - the std::regex
flags - the match flags

[edit] Return value

Returns the result containing the replacements.

[edit] See also

`
std::regex_constants::match_flag_type
std::basic_regex
std::regex_iterator