cpp11/regex1.cc

29 lines
577 B
C++
Raw Permalink Normal View History

2012-05-25 07:49:38 -07:00
// 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;
}
}
}