Created
October 18, 2012 09:06
-
-
Save filsinger/3910580 to your computer and use it in GitHub Desktop.
C++11 : Split a string using regex
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 <regex> | |
#include <string> | |
#include <vector> | |
std::vector<std::string> Split(const std::string& str, const std::string& regex) | |
{ | |
return {std::sregex_token_iterator(str.begin(), str.end(), std::regex(regex), -1), std::sregex_token_iterator()}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is inappropriate to pass a temporary regex
std::regex(regex)
to the iterator.If you are getting:
Then please see this Stack Overflow question.