#include "stdafx.h"
#include <regex>
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(int argc, char* argv[])
{
// 正则替换
puts("//c++ 0x regex_replace()");
string str = "Hello 333world";
tr1::regex rx("\\d+world");
string replacement = "planet";
string str2 = tr1::regex_replace(str, rx, replacement);
cout << "result:" << str2 << endl;
// map + auto
puts("\r\n//map + auto");
map<string, string> m;
m["aaa"] = "a111111";
m["bbb"] = "b22222";
m["ccc"] = "c33333";
for(auto i = m.begin(); i != m.end(); i++)
{
cout << i->first << i->second << endl;
}
// c++ 0x regex_match()
puts("\r\n//c++ 0x regex_match() ");
const regex p("(\\w+) \\w+ (\\d+) \\w+ (\\d+).*");
char *s = "aaa bbb 333 eee 555";
cmatch re;
bool ret = regex_match(s, re, p);
//if (ret)
{
string t;
for(auto i = re.begin(); i != re.end(); i++)
{
t = i->first;
t = t.substr(0, i->second - i->first);
cout << t << endl;
}
}
// c++ 0x regex_search()
puts("\r\n//c++ 0x regex_search()");
char *s2 = "hello world. 123";
regex p2("\\d+", tr1::regex_constants::icase);
cmatch re2;
regex_search(s2, re2, p2);
cout << "Matched \"" << re2.str()
<< "\" after \"" << re2.prefix()
<< "\" at offset: " << re2.position()
<< " with length: " << re2.length()
<< endl;
cout << tr1::regex r"(Hello "world")";
getchar();
return 0;
}