The Wayback Machine - https://web.archive.org/web/20180226131859/http://ja.cppreference.com:80/w/cpp/regex/regex_replace
名前空間
変種
操作

std::regex_replace

提供: cppreference.com
< cpp‎ | regex

 
 
正規表現ライブラリ
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_regex(C++11)
sub_match(C++11)
match_results(C++11)
アルゴリズム
Original:
Algorithms
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
regex_match(C++11)
regex_search(C++11)
regex_replace(C++11)
イテレータ
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
regex_iterator(C++11)
regex_token_iterator(C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
regex_error(C++11)
形質
Original:
Traits
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
regex_traits(C++11)
定数
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
syntax_option_type(C++11)
match_flag_type(C++11)
error_type(C++11)
 
ヘッダ <regex> で定義
template<class OutputIt, class BidirIt,

          class Traits, class CharT,
          class STraits, class SAlloc >
OutputIt regex_replace( OutputIt out, BidirIt first, BidirIt last,
                        conststd::basic_regex<CharT,Traits>& e,
                        conststd::basic_string<CharT,STraits,SAlloc>& fmt,
                        std::regex_constants::match_flag_type flags =

                            std::regex_constants::match_default);
(1) (C++11およびそれ以降)
template<class OutputIt, class BidirIt,

          class Traits, class CharT >
OutputIt regex_replace( OutputIt out, BidirIt first, BidirIt last,
                        conststd::basic_regex<CharT,Traits>& e,
                        const CharT* fmt,
                        std::regex_constants::match_flag_type flags =

                            std::regex_constants::match_default);
(2) (C++11およびそれ以降)
template<class Traits, class CharT,

          class STraits, class SAlloc,
          class FTraits, class FAlloc >
std::basic_string<CharT,STraits,SAlloc>
    regex_replace(conststd::basic_string<CharT,STraits,SAlloc>& s,
                   conststd::basic_regex<CharT,Traits>& e,
                   conststd::basic_string<CharT,FTraits,FAlloc>& fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default);
(3) (C++11およびそれ以降)
template<class Traits, class CharT,

          class STraits, class SAlloc >
std::basic_string<CharT,STraits,SAlloc>
    regex_replace(conststd::basic_string<CharT,STraits,SAlloc>& s,
                   conststd::basic_regex<CharT,Traits>& e,
                   const CharT* fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default);
(4) (C++11およびそれ以降)
template<class Traits, class CharT,

          class STraits, class SAlloc >
std::basic_string<CharT>
    regex_replace(const CharT* s,
                   conststd::basic_regex<CharT,Traits>& e,
                   conststd::basic_string<CharT,STraits,SAlloc>& fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default);
(5) (C++11およびそれ以降)
template<class Traits, class CharT >

std::basic_string<CharT>
    regex_replace(const CharT* s,
                   conststd::basic_regex<CharT,Traits>& e,
                   const CharT* fmt,
                   std::regex_constants::match_flag_type flags =

                       std::regex_constants::match_default);
(6) (C++11およびそれ以降)
1)
std::regex_iteratorまるで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に残りの非マッチした文字をコピーします.
Original:
Constructs a std::regex_iterator object 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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
一致するものがない場合には、そのまま、outにシーケンス全体をコピーします。.
Original:
If there are no matches, copies the entire sequence into out as-is.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
flagsstd::regex_constants::format_no_copy含まれている場合、非マッチした部分シーケンスがoutにコピーされません.
Original:
If flags contains std::regex_constants::format_no_copy, the non-matched subsequences are not copied into out.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
flagsstd::regex_constants::format_first_onlyが含まれている場合は、最初に一致したもののみが置換されます.
Original:
If flags contains std::regex_constants::format_first_only, only the first match is replaced.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
1)と同じですが、フォーマットされた交換はm.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags)を呼び出したかのように実行されます
Original:
same as 1), but the formatted replacement is performed as if by calling m.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3-4)
タイプresultの空の文字列std::basic_string<CharT, ST, SA>を構築し、std::regex_replace(std::back_inserter(result), s.begin(), s.end(), e, fmt, flags)呼び出し.
Original:
Constructs an empty string 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).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5-6)
タイプresultの空の文字列std::basic_string<CharT>を構築し、std::regex_replace(std::back_inserter(result), s, s +std::char_traits<CharT>::length(s), e, fmt, flags)呼び出し.
Original:
Constructs an empty string 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).
The text has been machine-translated via Google Translate.
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.
型の要件
-
OutputItOutputIterator

の要求を満足しなければなりません。

-
BidirItBidirectionalIterator

の要求を満足しなければなりません。

[編集]値を返します

1-2)
出力イテレータoutのコピーを返します。.
Original:
Returns a copy of the output iterator out.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3-6)
出力を含む文字列を返しますresult.
Original:
Returns the string result which contains the output.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]例外

std::regex_errorを示すためにエラー状態をスローすることがあります.
Original:
May throw std::regex_error to indicate an エラー状態.
The text has been machine-translated via Google Translate.
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

[編集]参照

文字列の任意の部分に正規表現を一致させようとします
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.

(関数テンプレート)[edit]
マッチングに固有のオプション
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)[edit]
close