std::regex_iterator
De cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
template< class BidirIt, |
(desde C++11) | |
std::regex_iterator
es un ForwardIterator
de sólo lectura que accede a los partidos individuales de una expresión regular dentro de la secuencia de caracteres subyacente .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.
En la construcción, y en cada incremento, llama std::regex_search y recuerda el resultado (es decir, guarda una copia de la std::match_results<BidirIt> valor). El primer objeto se puede leer cuando el iterador está construido o cuando la cancelación de referencia del primero que se hace. De lo contrario, desreferencia sólo devuelve una copia de la más reciente obtenida partido 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.
El valor predeterminado construido
std::regex_iterator
es el iterador de final de secuencia. Cuando un std::regex_iterator
válido se incrementa después de alcanzar el último partido (std::regex_search vuelve false), se hace igual a la iterador de final de secuencia. Desreferenciación o incrementarlo aún más invoca un comportamiento 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.
You can help to correct and verify the translation. Click here for instructions.
Una implementación típica de
std::regex_iterator
tiene el comienzo y los iteradores de extremo para la secuencia subyacente (dos instancias de BidirIt), un puntero a la expresión regular (const regex_type*) y las banderas de partido (std::regex_constants::match_flag_type), y la coincidencia actual (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.
Contenido |
[editar] Tipo de requisitos
-BidirIt must meet the requirements of BidirectionalIterator .
|
[editar] Especializaciones
Varias especializaciones comunes para los tipos de caracteres de secuencia se definen:
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.
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 miembros
Miembro de 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> |
[editar] Las funciones miembro
construye una nueva 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. (miembro público función) | |
(destructor) (implícitamente declarado) |
destructs a regex_iterator, including the cached value (miembro público función) |
sustituye a 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. (miembro público función) | |
compara dos 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. (miembro público función) | |
obtiene una referencia a la actual match accesses un miembro de la partida 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. (miembro público función) | |
avanza el regex_iterator a la siguiente coincidencia 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. (miembro público función) |
[editar] Notas
Es responsabilidad del programador asegurarse de que el objeto std::basic_regex pasa al constructor del iterador sobrevive el iterador. Debido a que el iterador almacena un puntero a la expresión regular, incrementando el iterador después de la expresión regular fue destruido accede a un puntero colgante .
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.
Si la parte de la expresión regular que coincide es sólo una afirmación (
^
, $
, \b
, \B
), el partido almacenada en el iterador es un partido de longitud cero, es decir, 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.
[editar] Ejemplo
#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
[editar] Ver también
(C++11) |
identifica una coincidencia de expresión regular, incluyendo todos los partidos de sub-expresión 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. (clase de plantilla) |
(C++11) |
comprobar si una expresión regular ocurre en cualquier lugar dentro de una cadena 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. (función de plantilla) |