Espaços nominais
Variantes
Acções

std::regex_iterator

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.
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.
regex_iterator
(C++11)
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)
 
template<

    class BidirIt,
    class CharT = typename std::iterator_traits<BidirIt>::value_type,
    class Traits = std::regex_traits<CharT>

> class regex_iterator
(desde C++11)
std::regex_iterator é um ForwardIterator somente leitura que acessa os jogos individuais de uma expressão regular dentro da seqüência de caracteres de base.
Original:
std::regex_iterator is a read-only ForwardIterator that accesses the individual matches of a regular expression within the underlying character sequence.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Na construção, e em cada incremento, ele chama std::regex_search e lembra o resultado (ou seja, salva uma cópia do std::match_results<BidirIt> valor). O primeiro objeto pode ser lido quando o iterador é construído ou quando o dereferencing primeiro é feito. Caso contrário, dereferencing retorna apenas uma cópia do jogo regex obtido mais recentemente.
Original:
On construction, and on every increment, it calls std::regex_search and remembers the result (that is, saves a copy of the value std::match_results<BidirIt>). The first object may be read when the iterator is constructed or when the first dereferencing is done. Otherwise, dereferencing only returns a copy of the most recently obtained regex match.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
O padrão construído std::regex_iterator é o iterador de fim de seqüência. Quando um std::regex_iterator válido é incrementado depois de atingir o último jogo (std::regex_search retornos false), torna-se igual ao iterador de fim de seqüência. Dereferencing ou incrementá-lo ainda mais invoca comportamento indefinido.
Original:
The default-constructed std::regex_iterator is the end-of-sequence iterator. When a valid std::regex_iterator is incremented after reaching the last match (std::regex_search returns false), it becomes equal to the end-of-sequence iterator. Dereferencing or incrementing it further invokes undefined behavior.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Uma implementação típica de std::regex_iterator detém a começar e os iteradores finais para a seqüência subjacente (duas instâncias de BidirIt), um ponteiro para a expressão regular (const regex_type*) e as bandeiras de correspondência (std::regex_constants::match_flag_type), eo jogo atual (std::match_results<BidirIt>).
Original:
A typical implementation of std::regex_iterator holds the begin and the end iterators for the underlying sequence (two instances of BidirIt), a pointer to the regular expression (const regex_type*) and the match flags (std::regex_constants::match_flag_type), and the current match (std::match_results<BidirIt>).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Índice

[editar] Requisitos de tipo

-
BidirIt must meet the requirements of BidirectionalIterator.

[editar] Especializações

Várias especializações para tipos de seqüência de caracteres comuns são definidas:
Original:
Several specializations for common character sequence types are defined:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Defined in header <regex>
Tipo
Original:
Type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
cregex_iterator regex_iterator<const char*>
wcregex_iterator regex_iterator<const wchar_t*>
sregex_iterator regex_iterator<std::string::const_iterator>
wsregex_iterator regex_iterator<std::wstring::const_iterator>

[editar] Tipos de membro

Tipo de membro
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
value_type std::match_results<BidirIt>
difference_type std::ptrdiff_t
pointer const value_type*
reference const value_type&
iterator_category std::forward_iterator_tag
regex_type basic_regex<CharT, Traits>

[editar] Funções de membro

constrói um novo regex_iterator
Original:
constructs a new regex_iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)
(destructor)
(declarada implicitamente)
destructs a regex_iterator, including the cached value
(função pública membro)
substitui um regex_iterator
Original:
replaces a regex_iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)
compara dois regex_iterators
Original:
compares two regex_iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)
obtém uma referência para a corrente match
accesses um membro do jogo actual
Original:
obtains a reference to the current match
accesses a member of the current match
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)
avança a regex_iterator para o próximo jogo
Original:
advances the regex_iterator to the next match
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)

[editar] Notas

É responsabilidade do programador para garantir que o objeto std::basic_regex passado para o construtor do iterador sobrevive o iterador. Porque o iterador armazena um ponteiro para a regex, incrementando o iterador após a regex foi destruído acessa um ponteiro dangling.
Original:
It is the programmer's responsibility to ensure that the std::basic_regex object passed to the iterator's constructor outlives the iterator. Because the iterator stores a pointer to the regex, incrementing the iterator after the regex was destroyed accesses a dangling pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se a parte da expressão regular que combinava é apenas uma afirmação (^, $, \b, \B), o jogo armazenado no iterator é um jogo de comprimento zero, isto é, match[0].first == match[0].second.
Original:
If the part of the regular expression that matched is just an assertion (^, $, \b, \B), the match stored in the iterator is a zero-length match, that is, match[0].first == match[0].second.
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 <regex>
#include <iterator>
#include <iostream>
 
int main()
{
    const std::string text = "Quick brown fox.";
 
    std::regex re("[^\\s]+");
    auto beg = std::sregex_iterator(text.begin(), text.end(), re);
    auto end = std::sregex_iterator();
 
    std::cout << "The number of words is " << std::distance(beg, end) << '\n';
}

Saída:

The number of words is 3

[editar] Veja também

identifica uma correspondência de expressão regular, incluindo todos os jogos sub-expressão
Original:
identifies one regular expression match, including all sub-expression matches
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(modelo de classe) [edit]
verificar se uma expressão regular ocorre em qualquer lugar dentro de uma cadeia
Original:
check if a regular expression occurs anywhere within a string
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)