정리/정규표현식
[C/C++] 정규표현식 사용방법 연습
2744m
2018. 10. 10. 16:53
/*---------기본-------------*/
#include <regex>
using namespace std;
int main(){
regex 변수명A("정규표현식");
string 변수명B = "문자열";
regex_match(B,A); // 표현식에 부합되면 true 반환, 아니면 false 반환
}
//--------------연습-----------------------//
#include <iostream>
#include <regex>
using namespace std;
int main() {
regex comp1("[a-z]+");
regex comp2("[a-z]*");
string str1 = "abc";
string str2 = "aBc";
if (regex_match(str1, comp1)) cout << "참";
else cout << "거짓";
cout << '\n';
if (regex_match(str2, comp1)) cout << "참";
else cout << "거짓";
cout << '\n';
if (regex_match(str1, comp2)) cout << "참";
else cout << "거짓";
cout << '\n';
if (regex_match(str2, comp2)) cout << "참";
else cout << "거짓";
}
....
출력결과:
참
거짓
참
거짓