std::regex_replace
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
ヘッダ <regex> で定義 | ||
template<class OutputIt, class BidirIt, class Traits, class CharT, | (1) | (C++11およびそれ以降) |
template<class OutputIt, class BidirIt, class Traits, class CharT > | (2) | (C++11およびそれ以降) |
template<class Traits, class CharT, class STraits, class SAlloc, | (3) | (C++11およびそれ以降) |
template<class Traits, class CharT, class STraits, class SAlloc > | (4) | (C++11およびそれ以降) |
template<class Traits, class CharT, class STraits, class SAlloc > | (5) | (C++11およびそれ以降) |
template<class Traits, class CharT > std::basic_string<CharT> | (6) | (C++11およびそれ以降) |
i
によってstd::regex_iterator<BidirIt, CharT, traits> i(first, last, e, flags)オブジェクトを構築し、シーケンス内e
[first,last)
のすべての試合をステップ実行するためにそれを使用しています。このような各マッチm
ため、as-isのm.prefix()
に非整合subsequenceを(out
)コピーしてm.format(out, fmt, flags)を呼び出したかのようにフォーマットされた置換文字列と一致する部分列を置き換えます。これ以上マッチが発見された場合は、out
に残りの非マッチした文字をコピーします.i
as if by std::regex_iterator<BidirIt, CharT, traits> i(first, last, e, flags), and uses it to step through every match of e
within the sequence [first,last)
. For each such match m
, copies the non-matched subsequence (m.prefix()
) into out
as-is and then replaces the matched subsequence with the formatted replacement string as if by calling m.format(out, fmt, flags). When no more matches are found, copies the remaining non-matched characters to out
.You can help to correct and verify the translation. Click here for instructions.
out
にシーケンス全体をコピーします。.out
as-is.You can help to correct and verify the translation. Click here for instructions.
flags
std::regex_constants::format_no_copy含まれている場合、非マッチした部分シーケンスがout
にコピーされません.flags
contains std::regex_constants::format_no_copy, the non-matched subsequences are not copied into out
.You can help to correct and verify the translation. Click here for instructions.
flags
std::regex_constants::format_first_onlyが含まれている場合は、最初に一致したもののみが置換されます.flags
contains std::regex_constants::format_first_only, only the first match is replaced.You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
result
の空の文字列std::basic_string<CharT, ST, SA>を構築し、std::regex_replace(std::back_inserter(result), s.begin(), s.end(), e, fmt, flags)呼び出し.result
of type std::basic_string<CharT, ST, SA> and calls std::regex_replace(std::back_inserter(result), s.begin(), s.end(), e, fmt, flags).You can help to correct and verify the translation. Click here for instructions.
result
の空の文字列std::basic_string<CharT>を構築し、std::regex_replace(std::back_inserter(result), s, s +std::char_traits<CharT>::length(s), e, fmt, flags)呼び出し.result
of type std::basic_string<CharT> and calls std::regex_replace(std::back_inserter(result), s, s +std::char_traits<CharT>::length(s), e, fmt, flags).You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集]パラメータ
first, last | - | イテレータのペアとして表される入力文字シーケンス Original: the input character sequence, represented as a pair of iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
s | - | はstd :: basic_stringのまたは文字配列として表される入力文字シーケンス Original: the input character sequence, represented as std::basic_string or character array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
e | - | のstd :: basic_regex入力シーケンスと照合されます Original: the std::basic_regex that will be matched against the input sequence The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
flags | - | マッチタイプstd::regex_constants::match_flag_typeのフラグ Original: the match flags of type std::regex_constants::match_flag_type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
fmt | - | 正規表現置換のフォーマット文字列には、正確な構文は flags の値に依存します Original: the regex replacement format string, exact syntax depends on the value of flags The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
out | - | 出力には、イテレータの置換の結果を格納する Original: output iterator to store the result of the replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
型の要件 | ||
-OutputIt は OutputIterator の要求を満足しなければなりません。 | ||
-BidirIt は BidirectionalIterator の要求を満足しなければなりません。 |
[編集]値を返します
out
のコピーを返します。.out
.You can help to correct and verify the translation. Click here for instructions.
result
.result
which contains the output.You can help to correct and verify the translation. Click here for instructions.
[編集]例外
You can help to correct and verify the translation. Click here for instructions.
[編集]例
#include <iostream>#include <regex>#include <string>int main(){std::string text ="Quick brown fox";std::regex vowel_re("a|o|e|u|i");std::cout<< std::regex_replace(text, vowel_re, "[$&]")<<'\n';}
出力:
Q[u][i]ck br[o]wn f[o]x
[編集]参照
(C++11) | 文字列の任意の部分に正規表現を一致させようとします Original: attempts to match a regular expression to any part of the character sequence The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) |
(C++11) | マッチングに固有のオプション Original: options specific to matching The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (typedef) |