std::regex_iterator
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
template< class BidirIt, |
(dal C++11) | |
std::regex_iterator
è di sola lettura ForwardIterator
che accede alle singole partite di un'espressione regolare all'interno della sequenza di caratteri di 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.
You can help to correct and verify the translation. Click here for instructions.
In costruzione, e su ogni incremento, chiama std::regex_search e ricorda il risultato (che, salva una copia del std::match_results<BidirIt> valore). Il primo oggetto può essere letto quando l'iteratore è costruito o quando la dereferenziazione primo fatto. In caso contrario, dereferenziare solo restituisce una copia delle partite più recentemente ottenuto regex.
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.
You can help to correct and verify the translation. Click here for instructions.
L'impostazione predefinita-costruito
std::regex_iterator
è la fine-di-sequenza di iteratore. Quando un std::regex_iterator
valido viene incrementato dopo aver raggiunto l'ultima partita (std::regex_search ritorna false), diventa uguale alla fine-di-sequenza di iteratore. Dereferenziazione o incrementarlo richiede ulteriori comportamento indefinito.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.
You can help to correct and verify the translation. Click here for instructions.
Una tipica implementazione di
std::regex_iterator
tiene il punto d'inizio e di fine per gli iteratori la sequenza sottostante (due istanze di BidirIt), un puntatore per l'espressione regolare (const regex_type*) e le bandiere (std::regex_constants::match_flag_type incontro), e la corrispondenza corrente (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.
You can help to correct and verify the translation. Click here for instructions.
Indice |
[modifica] Tipo requisiti
-BidirIt must meet the requirements of BidirectionalIterator .
|
[modifica] Specializzazioni
Diverse specializzazioni per i tipi più comuni sequenze di caratteri sono definiti:
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.
You can help to correct and verify the translation. Click here for instructions.
Definizione nell'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> |
[modifica] Membri tipi
Membro tipo
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> |
[modifica] Membri funzioni
costruisce un nuovo 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. (metodo pubblico) | |
(destructor) (dichiarato in modo implicito) |
destructs a regex_iterator, including the cached value (metodo pubblico) |
sostituisce un 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. (metodo pubblico) | |
confronta due 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. (metodo pubblico) | |
ottiene un riferimento alla corrente match accesses un membro della corrispondenza corrente 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. (metodo pubblico) | |
fa avanzare il regex_iterator al prossima partita 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. (metodo pubblico) |
[modifica] Note
E 'responsabilità del programmatore garantire che l'oggetto std::basic_regex passato al costruttore dell'iteratore sopravvive l'iteratore. Poiché l'iteratore memorizza un puntatore alla regex, incrementando l'iteratore dopo la regex è stato distrutto accede a un puntatore penzoloni.
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.
You can help to correct and verify the translation. Click here for instructions.
Se la parte dell'espressione regolare che ha trovato è solo un'affermazione (
^
, $
, \b
, \B
), la partita memorizzato nel iteratore è una corrispondenza di lunghezza zero, cioè, 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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Esempio
#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'; }
Output:
The number of words is 3
[modifica] Vedi anche
(C++11) |
identifica una partita di espressione regolare, inclusi tutti i sub-espressione partite 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. (classe template) |
(C++11) |
verificare se una espressione regolare si verifica ovunque all'interno di una stringa 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. (funzione di modello) |