std::match_results<BidirIt,Alloc>::format
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Classes | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Algorithms | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Iterators | ||||
(C++11) | ||||
(C++11) | ||||
| Exceptions | ||||
(C++11) | ||||
| Traits | ||||
(C++11) | ||||
| Constants | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Regex Grammar | ||||
(C++11) |
| Member functions | ||||
| State | ||||
| Element access | ||||
| Iterators | ||||
| Format | ||||
match_results::format | ||||
| Modifiers | ||||
| Non-member functions | ||||
(until C++20) | ||||
| template< class OutputIt > OutputIt format( OutputIt out, |
(1) | (since C++11) |
| template< class OutputIt, class ST, class SA > OutputIt format( OutputIt out, |
(2) | (since C++11) |
| template< class ST, class SA > std::basic_string<char_type,ST,SA> |
(3) | (since C++11) |
| string_type format( const char_type* fmt_s, std::regex_constants::match_flag_type flags = |
(4) | (since C++11) |
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.
Contents |
[edit] Parameters
| fmt_begin, fmt_end | - | pointers to a range of characters defining the format character sequence |
| fmt | - | std::basic_string defining the format character sequence |
| fmt_s | - | pointer to a null-terminated character string defining the format character sequence |
| out | - | iterator that the resulting character sequence is copied to |
| flags | - | std::regex_constants::match_flag_type bitmask specifying which format specifiers and escape sequences are recognized |
| Type requirements | ||
-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
| (C++11) |
replaces occurrences of a regular expression with formatted replacement text (function template) [edit] |
| (C++11) |
options specific to matching (typedef) [edit] |