std::match_results<BidirIt,Alloc>::format
OutputIt format( OutputIt out,
const char_type* fmt_first, const char_type* fmt_last,
std::regex_constants::match_flag_type flags =
OutputIt format( OutputIt out,
const basic_string<char_type,ST,SA>& fmt,
std::regex_constants::match_flag_type flags =
std::basic_string <char_type,ST,SA>
format( const std::basic_string <char_type,ST,SA>& fmt,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_flag_type flags =
format
outputs a format string, replacing any format specifiers or escape sequences in that string with match data from *this.
[
fmt_first,
fmt_last)
. The resulting character sequence is copied to out.The flags bitmask determines which format specifiers and escape sequences are recognized.
The behavior of format
is undefined if ready() != true.
[edit] Parameters
OutputIt
must meet the requirements of LegacyOutputIterator.
[edit] Return value
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Example
#include <iostream> #include <regex> #include <string> int main() { std::string s = "for a good time, call 867-5309"; std::regex phone_regex("\\d{3}-\\d{4}"); std::smatch phone_match; if (std::regex_search (s, phone_match, phone_regex)) { std::string fmt_s = phone_match.format( "$`" // $` means characters before the match "[$&]" // $& means the matched characters "$'"); // $' means characters following the match std::cout << fmt_s << '\n'; } }
Output:
for a good time, call [867-5309]
[edit] See also
(function template) [edit]