Created
January 21, 2014 16:09
-
-
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}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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