- C 标准库
- C 标准库
- C++ 标准库
- C++ 库 - 主页
- C++ 库 - <fstream>
- C++ 库 - <iomanip>
- C++ 库 - <ios>
- C++ 库 - <iosfwd>
- C++ 库 - <iostream>
- C++ 库 - <istream>
- C++ 库 - <ostream>
- C++ 库 - <sstream>
- C++ 库 - <streambuf>
- C++ 库 - <原子>
- C++ 库 - <复杂>
- C++ 库 - <异常>
- C++ 库 - <功能>
- C++ 库 - <限制>
- C++ 库 - <语言环境>
- C++ 库 - <内存>
- C++ 库 - <新>
- C++ 库 - <数字>
- C++ 库 - <正则表达式>
- C++ 库 - <stdexcept>
- C++ 库 - <字符串>
- C++ 库 - <线程>
- C++ 库 - <元组>
- C++ 库 - <类型信息>
- C++ 库 - <实用程序>
- C++ 库 - <valarray>
C++ 正则表达式库 - regex_token_iterator
描述
它是一个正则表达式标记迭代器。
宣言
以下是 std::regex_token_iterator 的声明。
template <class BidirectionalIterator,
class charT=typename iterator_traits<BidirectionalIterator>::value_type,
class traits=regex_traits<charT> > class regex_token_iterator;
C++11
template <class BidirectionalIterator,
class charT=typename iterator_traits<BidirectionalIterator>::value_type,
class traits=regex_traits<charT> > class regex_token_iterator;
C++14
template <class BidirectionalIterator,
class charT=typename iterator_traits<BidirectionalIterator>::value_type,
class traits=regex_traits<charT> > class regex_token_iterator;
参数
Bi DirectionIterator - 它是一种双向迭代器类型,可迭代目标字符序列。
charT - 它是一种 char 类型。
特征- 它是正则表达式特征类型。
返回值
它返回一个带有结果序列的字符串对象。
例外情况
No-noexcept - 该成员函数从不抛出异常。
例子
在下面的 std::regex_token_iterator 示例中。
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>
int main() {
std::string text = "Tutorialspoint india pvt ltd.";
std::regex ws_re("\\s+");
std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
std::string html = "<p><a href=\"http://tutorialspoint.com\">google</a> "
"< a HREF =\"http://indiabbc.com\">cppreference</a>\n</p>";
std::regex url_re("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"", std::regex::icase);
std::copy( std::sregex_token_iterator(html.begin(), html.end(), url_re, 1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}
输出应该是这样的 -
Tutorialspoint india pvt ltd. http://tutorialspoint.com http://indiabbc.com
正则表达式.htm