Espaços nominais
Variantes
Acções

std::regex_replace

Da cppreference.com
< cpp‎ | regex

 
 
Biblioteca de expressões regulares
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Algoritmos
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_replace
(C++11)
Iteradores
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exceções
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Características
Original:
Traits
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Constantes
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
 
Definido no cabeçalho <regex>
template< class OutputIt, class BidirIt,

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

                            std::regex_constants::match_default );
(1) (desde C++11)
template< class OutputIt, class BidirIt,

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

                            std::regex_constants::match_default );
(2) (desde C++11)
template< class Traits, class CharT,

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

                       std::regex_constants::match_default );
(3) (desde C++11)
template< class Traits, class CharT,

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

                       std::regex_constants::match_default );
(4) (desde C++11)
template< class Traits, class CharT,

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

                       std::regex_constants::match_default );
(5) (desde C++11)
template< class Traits, class CharT >

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

                       std::regex_constants::match_default );
(6) (desde C++11)
1)
Constrói um objeto std::regex_iterator i como se por std::regex_iterator<BidirIt, CharT, traits> i(first, last, e, flags), e usa-lo para percorrer todos os jogos de e dentro do [first,last) seqüência. Para cada partida m tal, copia a subseqüência não-pareado (m.prefix()) em out como está e então substitui o subseqüência combinado com a cadeia de substituição formatado como se chamando m.format(out, fmt, flags). Quando não há mais jogos são encontrados, copia os restantes não emparelhadas caracteres para 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.
Se não houver partidas, copia toda a seqüência em out como está.
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.
Se flags contém std::regex_constants::format_no_copy, as subseqüências não emparelhadas não são copiadas para 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.
Se flags contém std::regex_constants::format_first_only, apenas a primeira correspondência é substituído.
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)
mesmo que 1), mas a substituição formatada é executada como se ligando 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)
Constrói um result seqüência vazia de std::basic_string<CharT, ST, SA> tipo e chama 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)
Constrói um result seqüência vazia de std::basic_string<CharT> tipo e chama 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.

Índice

[editar] Parâmetros

first, last -
a seqüência de caracteres de entrada, representado como um par de iteradores
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 -
a seqüência de caracteres de entrada, representado como basic_string std :: ou matriz de caracteres
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 -
o std :: basic_regex que será comparado com a seqüência de entrada
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 -
as bandeiras jogo de std::regex_constants::match_flag_type tipo
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 -
a regex cadeia de formato de substituição, sintaxe exata depende do valor de 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 -
saída iterador para armazenar o resultado da substituição
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.
Type requirements
-
OutputIt must meet the requirements of OutputIterator.
-
BidirIt must meet the requirements of BidirectionalIterator.

[editar] Valor de retorno

1-2)
Retorna uma cópia do iterador de saída 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)
Retorna o result string que contém a saída.
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.

[editar] Exceções

Pode lançar std::regex_error para indicar um condição de erro.
Original:
May throw std::regex_error to indicate an condição de erro.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Exemplo

#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';
}

Saída:

Q[u][i]ck br[o]wn f[o]x

[editar] Veja também

tentativas de correspondem a uma expressão regular para qualquer parte da seqüência de caracteres
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.

(modelo de função) [edit]
opções específicas para correspondência
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]