Added some regex examples.

This commit is contained in:
Stephen M. McQuay
2012-05-25 08:49:38 -06:00
parent 530ccb5e37
commit 0a9c36b286
3 changed files with 60 additions and 2 deletions
+28
View File
@@ -0,0 +1,28 @@
// from https://github.com/sol-prog/regex_tutorial
#include <iostream>
#include <regex>
#include <string>
using namespace std;
int main() {
string input;
// traditional pcre escape
regex int_re {"(\\+|-)?\\d+"};
// ecmascript
regex float_re {"((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?((e|E)((\\+|-)?)[[:digit:]]+)?"};
while(cin >> input){
if (regex_match(input, int_re)) {
cout << "integer" << endl;
}
else if(regex_match(input, float_re)) {
cout << "float" << endl;
}
else {
cout << "nan" <<endl;
}
}
}