Created
February 22, 2018 19:51
-
-
Save wdberkeley/cca372484b610501efe37cdeb08e0e7e to your computer and use it in GitHub Desktop.
c++11 regex and version stripping
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 <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