Added some regex examples.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user