// ConsoleApplication1.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다. // #include "stdafx.h" #include // regex match bool match_regex(TCHAR* strData, TCHAR* pattern) { #ifdef _UNICODE wstring data(strData); wsmatch regexMatchResult; wregex mPattern(pattern); #else string data(strData); smatch regexMatchResult; regex mPattern(pattern); #endif return regex_match(data, regexMatchResult, mPattern); } int _tmain(int argc, _TCHAR* argv[]) { // 이름, 알파벳, 숫자, 특수문자 if (match_regex(_T("korea"), _T("(([가-힣]|[a-zA-Z0-9_]|[\\-\\[\\]\\(\\)\\{\\}])+)"))) cout << "TRUE" << endl; else cout << "FALSE" << endl; // 주민 번호 (6-7) if (match_regex(_T("881122-1234567"), _T("\\d{6}\\-\\d{7}"))) cout << "TRUE" << endl; else cout << "FALSE" << endl; // URL if (match_regex(_T("http://copynull.tistory.com"), _T("(ftp|http|https):\\/\\/(\\w+)(\\.\\w+)*(\\/([\\w\\d])+\\/{0,1})*"))) cout << "TRUE" << endl; else cout << "FALSE" << endl; // Network Interface MAC address if (match_regex(_T("ab-21-33-f5-c6-07"), _T("([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])"))) cout << "TRUE" << endl; else cout << "FALSE" << endl; // E-Mail Address if (match_regex(_T("copynull@nate.com"), _T("[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*[.][a-zA-Z]{2,3}"))) cout << "TRUE" << endl; else cout << "FALSE" << endl; // IP Address if (match_regex(_T("255.255.255.0"), _T("([1]?\\d{1,2}|[2][0-4]\\d|25[0-5])[.]([1]?\\d{1,2}|[2][0-4]\\d|25[0-5])[.]([1]?\\d{1,2}|[2][0-4]\\d|25[0-5])[.]([1]?\\d{1,2}|[2][0-4]\\d|25[0-5])"))) cout << "TRUE" << endl; else cout << "FALSE" << endl; return 0; } |