Skip to content

Instantly share code, notes, and snippets.

@jasonlvhit
Created October 18, 2014 04:33
Show Gist options
  • Save jasonlvhit/4dc78cf9c032cbfa6957 to your computer and use it in GitHub Desktop.
Save jasonlvhit/4dc78cf9c032cbfa6957 to your computer and use it in GitHub Desktop.
int main(){
std::string pattern = "^<([\\w|_]+)>\\s*::=\\s*(.*)";
std::regex p(pattern);
std::smatch piece;
string r = "<iter_stmt> ::= WHILE(<expression>) <stmt>";
std::regex_match(r, piece, p);
cout << piece.size() << endl;
for (size_t i = 0; i < piece.size(); ++i) {
std::ssub_match sub_match = piece[i];
std::string piece = sub_match.str();
std::cout << " submatch " << i << ": " << piece << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment