format
outputs a format string, replacing any format specifiers or escape sequences in that string with match data from *this.
1) The format character sequence is defined by the range [
fmt_first,
fmt_last)
. The resulting character sequence is copied to out.
2) The format character sequence is defined by the characters in fmt. The resulting character sequence is copied to out.
3,4)The format character sequence is defined by the characters in
fmtand
fmt_srespectively. The resulting character sequence is copied to a newly constructed
std::basic_string, which is returned.
The flags bitmask determines which format specifiers and escape sequences are recognized.
The behavior of format
is undefined if ready() != true.
OutputIt
must meet the requirements of LegacyOutputIterator. [edit] Return value
1,2) out
3,4) The newly constructed string containing resulting character sequence.
[edit] ExceptionsMay 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4