Last active
December 28, 2015 21:19
-
-
Save jslvtr/7564077 to your computer and use it in GitHub Desktop.
This is a way to get three parts out of a line, showing the output, written in C++.
This file contains 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
std::string text = "Hello sweet world" | |
// Create cmatch object to match `match_results` objects into string literals | |
std::cmatch matchStore; | |
// Create a regex object to contain the strings that are going to be matched against | |
std::regex reg("([A-z]+)[\\s]+([A-z]+)[\\s]+([A-z]+)"); | |
// `regex_search` will go through the string and store any matchings into `cm` | |
std::regex_search(text.c_str(), matchStore, reg); | |
for(int i = 1; i < matchStore.size(); i++) { | |
std::cout << "[" << matchStore[i] << "]" << std::endl; | |
} | |
// Will print out: | |
// [Hello] | |
// [sweet] | |
// [world] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment