Repeated Search
It’s quite convenient to iterate with std::regex_iterator
and std::regex_token_iterator
over the matched texts. std::regex_iterator
supports the matches and their capture groups. std::regex_token_iterator
supports more. You can address the components of each capture and by using a negative index, your can access the text between the matches.
std::regex_iterator
C++ defines the following four type synonyms for std::regex_iterator
.
typedef
cregex_iterator
regex_iterator
<
const
char
*>
typedef
wcregex_iterator
regex_iterator
<
const
wchar_t
*>
typedef
sregex_iterator
regex_iterator
<
std
::
string
::
const_iterator
>
typedef
wsregex_iterator
regex_iterator
<
std
::
wstring
::
const_iterator
>
You can use std::regex_iterator
to count the occurrences of the words in a text:
std::regex_iterator
// regexIterator.cpp
...
#include
<regex>
...
using
std
::
cout
;
std
::
string
text
{
"That's a (to me) amazingly frequent question...