#include <regex>
#include <string>
#include <fstream>
#include <iostream>
int main()
{
std::string phone =
"(\\()?(\\d{3})(\\))?([-. ])?(\\d{3})([-. ])?(\\d{4})";
std::regex r(phone);
std::smatch m;
std::string s;
std::string fmt = "$2.$5.$7";
std::ifstream fin("contacts.dat");
while (std::getline(fin, s)) {
std::cout << std::regex_replace(s, r, fmt) << std::endl;
}
return 0;
}
// from C++ Primer 5th(p.743)
// g++ xx.cpp -std=c++11
// gcc 4.9.2