std::match_results<BidirIt,Alloc>:: format
|
template
<
class
OutputIt
>
OutputIt format
(
OutputIt out,
|
(1) | (C++11以降) |
|
template
<
class
OutputIt,
class
ST,
class
SA
>
OutputIt format
(
OutputIt out,
|
(2) | (C++11以降) |
|
template
<
class
ST,
class
SA
>
std::
basic_string
<
char_type,ST,SA
>
|
(3) | (C++11以降) |
|
string_type format
(
const
char_type
*
fmt_s,
std::
regex_constants
::
match_flag_type
flags
=
|
(4) | (C++11以降) |
format
はフォーマット文字列を出力し、その文字列内のフォーマット指定子またはエスケープシーケンスを
*
this
からのマッチデータで置き換えます。
[
fmt_first
,
fmt_last
)
によって定義されます。結果の文字シーケンスは
out
にコピーされます。
flags ビットマスクは、どのフォーマット指定子とエスケープシーケンスが認識されるかを決定します。
format
の動作は、
ready
(
)
!
=
true
の場合、未定義です。
目次 |
パラメータ
| fmt_begin, fmt_end | - | フォーマット文字シーケンスを定義する文字範囲へのポインタ |
| fmt | - | std::basic_string フォーマット文字シーケンスを定義する |
| fmt_s | - | フォーマット文字シーケンスを定義するヌル終端文字列へのポインタ |
| out | - | 結果の文字シーケンスがコピーされるイテレータ |
| flags | - | std::regex_constants::match_flag_type どのフォーマット指定子とエスケープシーケンスが認識されるかを指定するビットマスク |
| 型要件 | ||
-
OutputIt
は
LegacyOutputIterator
の要件を満たさなければならない。
|
||
戻り値
例外
実装定義の例外をスローする可能性があります。
例
#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'; } }
出力:
for a good time, call [867-5309]
関連項目
|
(C++11)
|
正規表現の出現をフォーマットされた置換テキストで置き換える
(関数テンプレート) |
|
(C++11)
|
マッチングに固有のオプション
(typedef) |