C++ regex search()

Jmnote (토론 | 기여)님의 2023년 9월 29일 (금) 15:52 판 (새 문서: ==개요== ;C++ regex_search() <syntaxhighlight lang='cpp' run> #include <iostream> #include <string> #include <regex> using namespace std; int main () { string s ("this subject h...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

C++ regex_search()
C++
CPU
2.6s
MEM
171M
2.6s
Copy
#include <iostream>
#include <string>
#include <regex>
using namespace std;

int main ()
{
  string s ("this subject has a submarine as a subsequence");
  smatch m;
  regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"

  cout << "Target sequence: " << s << endl;
  cout << "Regular expression: /\\b(sub)([^ ]*)/" << endl;
  cout << "The following matches and submatches were found:" << endl;

  while (regex_search (s,m,e)) {
    for (auto x:m) std::cout << x << " ";
    cout << endl;
    s = m.suffix().str();
  }
}
Target sequence: this subject has a submarine as a subsequence
Regular expression: /\b(sub)([^ ]*)/
The following matches and submatches were found:
subject sub ject 
submarine sub marine 
subsequence sub sequence 


2 같이 보기

3 참고

[[분류: ]] [[분류: ]]