일상 코딩
[C++/CPP] 18.05 regular expressions, 정규 표현식 본문
728x90
C++ 온라인 컴파일러 사이트
- https://replit.com/~
- https://www.onlinegdb.com/online_c++_compiler
- https://cpp.sh/
- https://www.tutorialspoint.com/compile_cpp_online.php
#include<iostream>
#include<string>
#include<vector>
#include<regex>
using namespace std;
int main()
{
// regex re("\\d+"); // \d - digit인지?
// regex re("[ab]");
// regex re("[[:digit:]]{3}");
// regex re("[A-Z]+");
// regex re("[A-Z]{1,5}"); // 최소 1개, 최대 5개
regex re("([0-9]{1})([-]?)([0-9]{1,4})");
string str;
while(true)
{
getline(cin, str);
if (std::regex_match(str, re))
cout << "Match" << endl;
else
cout << "No Match" << endl;
// print matches
{
auto begin = std::sregex_iterator(str.begin(), str.end(), re);
auto end = std::sregex_iterator();
for(auto itr = begin; itr != end; ++itr)
{
std::smatch match = *itr;
cout << match.str() << " ";
}
cout << endl;
}
cout << endl;
}
return 0;
}
728x90
'C++ > 따배C++ 18강 입력과 출력' 카테고리의 다른 글
[C++/CPP] 18.07. Random Accessing File, read / write (0) | 2021.12.22 |
---|---|
[C++/CPP] 18.06. basic file i/o (0) | 2021.12.21 |
[C++/CPP] 18.04. stream states, input validation (0) | 2021.12.19 |
[C++/CPP] 18.03. 문자열 stream (0) | 2021.12.18 |
[C++/CPP] 18.02. ostream output (0) | 2021.12.17 |