目录

regex_token_iterator

描述 (Description)

它是一个正则表达式令牌迭代器。

声明 (Declaration)

以下是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;

参数 (Parameters)

  • BidirectionalIterator - 它是一种双向迭代器类型,它迭代目标字符序列。

  • charT - 它是一种char类型。

  • traits - 它是一种正则表达式特征类型。

返回值 (Return Value)

它返回一个带有结果序列的字符串对象。

异常 (Exceptions)

No-noexcept - 这个成员函数永远不会抛出异常。

例子 (Example)

在下面的示例中为std :: regex_token_iterator。

#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>
int main() {
   std::string text = "IoWiki 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://iowiki.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"));
}

输出应该是这样的 -

IoWiki
india
pvt
ltd.
http://iowiki.com
http://indiabbc.com
↑回到顶部↑
WIKI教程 @2018