Files
2025-10-25 03:02:53 +03:00

4.6 KiB
Raw Permalink Blame History

[re.alg.replace]

28 Text processing library [text]

28.6 Regular expressions library [re]

28.6.10 Regular expression algorithms [re.alg]

28.6.10.4 regex_replace [re.alg.replace]

🔗

template<class OutputIterator, class BidirectionalIterator, class traits, class charT, class ST, class SA> OutputIterator regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last, const basic_regex<charT, traits>& e, const basic_string<charT, ST, SA>& fmt, regex_constants::match_flag_type flags = regex_constants::match_default); template<class OutputIterator, class BidirectionalIterator, class traits, class charT> OutputIterator regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last, const basic_regex<charT, traits>& e, const charT* fmt, regex_constants::match_flag_type flags = regex_constants::match_default);

1

#

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

If no such matches are found and!(flags & regex_constants::format_no_copy), then callsout = copy(first, last, out)

If any matches are found then, for each such match:

If !(flags & regex_constants::format_no_copy), callsout = copy(m.prefix().first, m.prefix().second, out)

Then callsout = m.format(out, fmt, flags) for the first form of the function andout = m.format(out, fmt, fmt + char_traits::length(fmt), flags) for the second.

Finally, if such a match is found and !(flags & regex_constants::format_no_copy), callsout = copy(last_m.suffix().first, last_m.suffix().second, out) where last_m is a copy of the last match found.

If flags & regex_constants::format_first_only is nonzero, then only the first match found is replaced.

2

#

Returns: out.

🔗

template<class traits, class charT, class ST, class SA, class FST, class FSA> basic_string<charT, ST, SA> regex_replace(const basic_string<charT, ST, SA>& s, const basic_regex<charT, traits>& e, const basic_string<charT, FST, FSA>& fmt, regex_constants::match_flag_type flags = regex_constants::match_default); template<class traits, class charT, class ST, class SA> basic_string<charT, ST, SA> regex_replace(const basic_string<charT, ST, SA>& s, const basic_regex<charT, traits>& e, const charT* fmt, regex_constants::match_flag_type flags = regex_constants::match_default);

3

#

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

4

#

Returns: result.

🔗

template<class traits, class charT, class ST, class SA> basic_string<charT> regex_replace(const charT* s, const basic_regex<charT, traits>& e, const basic_string<charT, ST, SA>& fmt, regex_constants::match_flag_type flags = regex_constants::match_default); template<class traits, class charT> basic_string<charT> regex_replace(const charT* s, const basic_regex<charT, traits>& e, const charT* fmt, regex_constants::match_flag_type flags = regex_constants::match_default);

5

#

Effects: Constructs an empty string result of type basic_string and calls:regex_replace(back_inserter(result), s, s + char_traits::length(s), e, fmt, flags);

6

#

Returns: result.