Skip to content

Instantly share code, notes, and snippets.

@whoo24
Created January 21, 2014 16:09
Show Gist options
  • Save whoo24/8542950 to your computer and use it in GitHub Desktop.
Save whoo24/8542950 to your computer and use it in GitHub Desktop.
split blanket using c++ tr1 regex. output is below. {pa,tt} {e, rn}
#include "stdafx.h"
#include <regex>
#include <iostream>
#include <exception>
int _tmain(int argc, _TCHAR* argv[])
{
std::string source = "{pa,tt}, {e, rn}";
try
{
std::regex pattern("\\{.*?\\}", std::regex_constants::ECMAScript);
const std::sregex_token_iterator end;
std::sregex_token_iterator it(source.begin(), source.end(), pattern);
while( it != end )
{
std::cout << *it << std::endl;
++it;
}
}
catch( std::exception& e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment