Skip to content

Instantly share code, notes, and snippets.

@jslvtr
Last active December 28, 2015 21:19
Show Gist options
  • Save jslvtr/7563993 to your computer and use it in GitHub Desktop.
Save jslvtr/7563993 to your computer and use it in GitHub Desktop.
This is a way to get 3 words of a line that are space separated, sometimes with multiple spaces, written in C++.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment