티스토리 뷰
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <regex>
#ifdef _UNICODE
#define tcout wcout
#define tcin wcin
#define tstring wstring
#else
#define tcout cout
#define tcin cin
#define tstring string
#endif
#ifdef _UNICODE
#define tregex wregex
#define tcmatch wcmatch
#define tsmatch wsmatch
#else
#define tregex regex
#define tcmatch cmatch
#define tsmatch smatch
#endif
using namespace std;
void method1();
void method2();
void method3();
void method4();
void method5();
int _tmain(int argc, _TCHAR* argv[])
{
method1();
method2();
method3();
method4();
method5();
getchar();
return 0;
}
void method1()
{
tstring sourceString = _T("abc123");
tstring patternString = _T("c1");
tregex regexPattern(patternString);
tcout << regex_match(sourceString, regexPattern) << endl; // prints 0 (false)
tcout << regex_search(sourceString, regexPattern) << endl; // prints 1 (true)
}
void method2()
{
tstring sourceString = _T("abc123def456");
tstring patternString = _T("(\\d+)");
tstring replaceString = _T("<$1>");
tregex regexPattern(patternString);
tcout << regex_replace(sourceString, regexPattern, replaceString) << endl; // prints abc<123>def<456>
}
void method3()
{
tstring sourceString = _T("1:22:33:444");
tregex regexPattern(_T("(\\d{1,3}):(\\d{1,3}):(\\d{1,3}):(\\d{1,3})"));
tsmatch matchResults;
bool valid = regex_match(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl; // prints 1
tcout << "b2: " << matchResults[2] << endl; // prints 22
tcout << "b3: " << matchResults[3] << endl; // prints 33
tcout << "b4: " << matchResults[4] << endl; // prints 444
}
}
void method4()
{
tstring sourceString = _T("1:22:33:444");
tregex regexPattern(_T("(\\d+):(\\d+)"));
tsmatch matchResults;
bool valid = regex_search(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
}
}
void method5()
{
tstring sourceString = _T("1:22 33:444 5:66 777:88");
tregex regexPattern(_T("(\\d+):(\\d+)"));
tsmatch matchResults;
tstring::const_iterator start = sourceString.begin();
tstring::const_iterator close = sourceString.end();
while(regex_search(start, close, matchResults, regexPattern))
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
start = matchResults[0].second;
}
}
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <regex>
#ifdef _UNICODE
#define tcout wcout
#define tcin wcin
#define tstring wstring
#else
#define tcout cout
#define tcin cin
#define tstring string
#endif
#ifdef _UNICODE
#define tregex wregex
#define tcmatch wcmatch
#define tsmatch wsmatch
#else
#define tregex regex
#define tcmatch cmatch
#define tsmatch smatch
#endif
using namespace std;
void method1();
void method2();
void method3();
void method4();
void method5();
int _tmain(int argc, _TCHAR* argv[])
{
method1();
method2();
method3();
method4();
method5();
getchar();
return 0;
}
void method1()
{
tstring sourceString = _T("abc123");
tstring patternString = _T("c1");
tregex regexPattern(patternString);
tcout << regex_match(sourceString, regexPattern) << endl; // prints 0 (false)
tcout << regex_search(sourceString, regexPattern) << endl; // prints 1 (true)
}
void method2()
{
tstring sourceString = _T("abc123def456");
tstring patternString = _T("(\\d+)");
tstring replaceString = _T("<$1>");
tregex regexPattern(patternString);
tcout << regex_replace(sourceString, regexPattern, replaceString) << endl; // prints abc<123>def<456>
}
void method3()
{
tstring sourceString = _T("1:22:33:444");
tregex regexPattern(_T("(\\d{1,3}):(\\d{1,3}):(\\d{1,3}):(\\d{1,3})"));
tsmatch matchResults;
bool valid = regex_match(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl; // prints 1
tcout << "b2: " << matchResults[2] << endl; // prints 22
tcout << "b3: " << matchResults[3] << endl; // prints 33
tcout << "b4: " << matchResults[4] << endl; // prints 444
}
}
void method4()
{
tstring sourceString = _T("1:22:33:444");
tregex regexPattern(_T("(\\d+):(\\d+)"));
tsmatch matchResults;
bool valid = regex_search(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
}
}
void method5()
{
tstring sourceString = _T("1:22 33:444 5:66 777:88");
tregex regexPattern(_T("(\\d+):(\\d+)"));
tsmatch matchResults;
tstring::const_iterator start = sourceString.begin();
tstring::const_iterator close = sourceString.end();
while(regex_search(start, close, matchResults, regexPattern))
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
start = matchResults[0].second;
}
}
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <boost/regex.hpp>
#ifdef _UNICODE
#define tcout wcout
#define tcin wcin
#define tstring wstring
#else
#define tcout cout
#define tcin cin
#define tstring string
#endif
#ifdef _UNICODE
#define tregex wregex
#define tcmatch wcmatch
#define tsmatch wsmatch
#else
#define tregex regex
#define tcmatch cmatch
#define tsmatch smatch
#endif
using namespace std;
void method1();
void method2();
void method3();
void method4();
void method5();
int _tmain(int argc, _TCHAR* argv[])
{
method1();
method2();
method3();
method4();
method5();
getchar();
return 0;
}
void method1()
{
tstring sourceString = _T("abc123");
tstring patternString = _T("c1");
boost::tregex regexPattern(patternString);
tcout << boost::regex_match(sourceString, regexPattern) << endl; // prints 0 (false)
tcout << boost::regex_search(sourceString, regexPattern) << endl; // prints 1 (true)
}
void method2()
{
tstring sourceString = _T("abc123def456");
tstring patternString = _T("(\\d+)");
tstring replaceString = _T("<$1>");
boost::tregex regexPattern(patternString);
tcout << boost::regex_replace(sourceString, regexPattern, replaceString) << endl; // prints abc<123>def<456>
}
void method3()
{
tstring sourceString = _T("1:22:33:444");
boost::tregex regexPattern(_T("(\\d{1,3}):(\\d{1,3}):(\\d{1,3}):(\\d{1,3})"));
boost::tsmatch matchResults;
bool valid = boost::regex_match(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl; // prints 1
tcout << "b2: " << matchResults[2] << endl; // prints 22
tcout << "b3: " << matchResults[3] << endl; // prints 33
tcout << "b4: " << matchResults[4] << endl; // prints 444
}
}
void method4()
{
tstring sourceString = _T("1:22:33:444");
boost::tregex regexPattern(_T("(\\d+):(\\d+)"));
boost::tsmatch matchResults;
bool valid = boost::regex_search(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
}
}
void method5()
{
tstring sourceString = _T("1:22 33:444 5:66 777:88");
boost::tregex regexPattern(_T("(\\d+):(\\d+)"));
boost::tsmatch matchResults;
tstring::const_iterator start = sourceString.begin();
tstring::const_iterator close = sourceString.end();
while(boost::regex_search(start, close, matchResults, regexPattern))
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
start = matchResults[0].second;
}
}
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <boost/regex.hpp>
#ifdef _UNICODE
#define tcout wcout
#define tcin wcin
#define tstring wstring
#else
#define tcout cout
#define tcin cin
#define tstring string
#endif
#ifdef _UNICODE
#define tregex wregex
#define tcmatch wcmatch
#define tsmatch wsmatch
#else
#define tregex regex
#define tcmatch cmatch
#define tsmatch smatch
#endif
using namespace std;
void method1();
void method2();
void method3();
void method4();
void method5();
int _tmain(int argc, _TCHAR* argv[])
{
method1();
method2();
method3();
method4();
method5();
getchar();
return 0;
}
void method1()
{
tstring sourceString = _T("abc123");
tstring patternString = _T("c1");
boost::tregex regexPattern(patternString);
tcout << boost::regex_match(sourceString, regexPattern) << endl; // prints 0 (false)
tcout << boost::regex_search(sourceString, regexPattern) << endl; // prints 1 (true)
}
void method2()
{
tstring sourceString = _T("abc123def456");
tstring patternString = _T("(\\d+)");
tstring replaceString = _T("<$1>");
boost::tregex regexPattern(patternString);
tcout << boost::regex_replace(sourceString, regexPattern, replaceString) << endl; // prints abc<123>def<456>
}
void method3()
{
tstring sourceString = _T("1:22:33:444");
boost::tregex regexPattern(_T("(\\d{1,3}):(\\d{1,3}):(\\d{1,3}):(\\d{1,3})"));
boost::tsmatch matchResults;
bool valid = boost::regex_match(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl; // prints 1
tcout << "b2: " << matchResults[2] << endl; // prints 22
tcout << "b3: " << matchResults[3] << endl; // prints 33
tcout << "b4: " << matchResults[4] << endl; // prints 444
}
}
void method4()
{
tstring sourceString = _T("1:22:33:444");
boost::tregex regexPattern(_T("(\\d+):(\\d+)"));
boost::tsmatch matchResults;
bool valid = boost::regex_search(sourceString, matchResults, regexPattern);
tcout << sourceString.c_str() << _T(" : ") << (valid ? _T("valid") : _T("invalid")) << endl;
if(valid)
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
}
}
void method5()
{
tstring sourceString = _T("1:22 33:444 5:66 777:88");
boost::tregex regexPattern(_T("(\\d+):(\\d+)"));
boost::tsmatch matchResults;
tstring::const_iterator start = sourceString.begin();
tstring::const_iterator close = sourceString.end();
while(boost::regex_search(start, close, matchResults, regexPattern))
{
tcout << "b1: " << matchResults[1] << endl;
tcout << "b2: " << matchResults[2] << endl;
start = matchResults[0].second;
}
}
'Code > C C++' 카테고리의 다른 글
[MFC] Simplified MFC Structure (0) | 2010.04.24 |
---|---|
[MFC] Simplest MFC Program (0) | 2010.04.23 |
[C++/CLI] #pragma managed, #pragma unmanaged (0) | 2009.05.09 |
[C++/CLI] #pragma managed, #pragma unmanaged, Windows API (0) | 2009.05.09 |
[C++] 16진수 문자열을 2진수 문자열로 변환 (0) | 2009.04.19 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- tagREADYSTATE
- iText
- .net framework
- Sample Code
- AxWebBrowser
- 유틸리티
- 스크린캡쳐
- Rollback Rx
- autohotkey
- DotNetMagic
- jre
- AdSense숨기기
- ScreenHunter
- iTextSharp
- download.com
- 애드센스감추기
- READYSTATE_COMPLETE
- AdSense감추기
- WinAutomation
- windows
- Automation
- Regular Expressions
- Service pack
- registry
- Phalanger
- c#
- java
- Microsoft
- 애드센스숨기기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함