29 lines
577 B
C++
29 lines
577 B
C++
|
// 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;
|
||
|
}
|
||
|
}
|
||
|
}
|