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. |
<metanoindex/>
<tbody> </tbody> template< class BidirIt, class CharT = typename std::iterator_traits<BidirIt>::value_type, class Traits = std::regex_traits<CharT> > class regex_iterator |
(depuis C++11) | |
std::regex_iterator est un ForwardIterator en lecture seule qui permet d'accder aux diffrents matchs d'une expression rgulire dans la chane de caractres sous-jacent .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.
sur la construction et sur chaque augmentation, il appelle std::regex_search et se souvient du rsultat (qui est, enregistre une copie de la valeur
std::match_results<BidirIt>). Le premier objet peut tre lu lorsque l'itrateur est construit ou lorsque le drfrencement premier pas est fait. Sinon, le drfrencement retourne uniquement une copie de le match le plus rcemment obtenu 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.
La valeur par dfaut est construit
std::regex_iterator l'itrateur de fin de squence. Quand un std::regex_iterator valide est incrment aprs avoir atteint le dernier match (std::regex_search retours false), elle devient gale la fin de itrateur squence. drfrencement ou incrmenter il invoque par ailleurs un comportement indfini .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.
Une application typique de
std::regex_iterator dtient le dbut et de fin pour les itrateurs la squence sous-jacente (deux instances de BidirIt), un pointeur sur l'expression rgulire (const regex_type*) et les indicateurs de correspondance (std::regex_constants::match_flag_type), et le rsultat actuel (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.
Exigences de type
-BidirIt must meet the requirements of BidirectionalIterator.
|
Spcialisations
Plusieurs spcialisations pour les types courants de squence de caractres sont dfinies:
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> | |
Type d'
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>
|
Types de membres
| Type du membre | Dfinition |
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>
|
Fonctions membres
construit une nouvelle 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. (fonction membre publique) | |
(destructeur) (implicitement dclar) |
destructs a regex_iterator, including the cached value (fonction membre publique) |
remplace 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. (fonction membre publique) | |
compare deux 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. (fonction membre publique) | |
obtient une rfrence l'actuel match accesses un membre du match en cours 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. (fonction membre publique) | |
progrs de la regex_iterator pour le prochain match 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. (fonction membre publique) | |
Notes
Il est de la responsabilit du programmeur de s'assurer que l'objet std::basic_regex pass au constructeur de l'itrateur survit l'itrateur. Parce que l'itrateur stocke un pointeur vers la regex, l'incrmentation de l'itrateur aprs l'expression rationnelle a t dtruit accde un pointeur 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.
You can help to correct and verify the translation. Click here for instructions.
Si la partie de l'expression rgulire qui correspond est juste une affirmation (
^, $, \b, \B), le match stockes dans l'itrateur est un match de longueur nulle, c'est--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.
Exemple
#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';
}
Rsultat :
The number of words is 3
Voir aussi
(C++11) |
identifie une correspondance d'expression rgulire, y compris tous les matchs de la sous-expression 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 gnrique) |
(C++11) |
vrifier si une expression rgulire se produit n'importe o dans une chane 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. (fonction gnrique) |