Skip to content

Instantly share code, notes, and snippets.

@wdberkeley
Created February 22, 2018 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdberkeley/cca372484b610501efe37cdeb08e0e7e to your computer and use it in GitHub Desktop.
Save wdberkeley/cca372484b610501efe37cdeb08e0e7e to your computer and use it in GitHub Desktop.
c++11 regex and version stripping
#include <regex>
#include <iostream>
#include <string>
using namespace std;
int main() {
string input;
regex integer("([[:digit:]]+.[[:digit:]]+.[[:digit:]]+)(-.*)?");
smatch matches;
while (true) {
cout << "Version please." << endl;
cin >> input;
if (!cin || input == "q") return 0;
if (regex_search(input, matches, integer)) {
cout << "Version: " << matches[0].str() << endl;
cout << "Stripped version: " << matches[1].str() << endl;
} else {
cout << "That's not a version." << endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment