Thinking Different





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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;
}