名前空間
変種
操作

「cpp/regex/regex iterator/operator*」の版間の差分

提供: cppreference.com
 
23行: 23行:
 
#include <regex>
 
#include <regex>
 
   
 
   
int main() {
+
int main()
+
std::regex expression ("[1234]");
+
std::regex expression("[1234]");
std::string searchStr("1.1a2b3cjk34");
+
std::string searchStr("1.1a2b3cjk34");
std::regex_iterator<std::string::iterator> it ( searchStr.begin(), searchStr.end(), expression);
+
std::regex_iterator<std::string::iterator> end;
+
  
  while (it!=end) {
+
(
         std::cout << it->str();  
+
  it++;
+
it != ) {
}
+
         std::cout << it->str();
 +
}
 
}
 
}
 
  | output= 112334
 
  | output= 112334

2019年8月21日 (水) 08:52時点における最新版

const value_type& operator*() const;
(1) (C++11以上)
const value_type* operator->() const;
(2) (C++11以上)

現在の std::match_resultsregex_iterator から取り出します。

1) 現在の std::match_results を指す参照を返します。
2) 現在の std::match_results を指すポインタを返します。

[編集]

#include <iostream>
#include <string>
#include <regex>
 
int main()
{
    std::regex expression("[1234]");
    std::string searchStr("1.1a2b3cjk34");
 
    for (std::regex_iterator<std::string::iterator> it{
        searchStr.begin(), searchStr.end(), expression
    }, last{}; it != last; ++it) {
        std::cout << it->str();
    }
}

出力:

112334