cpp11/regex2.cc

29 lines
705 B
C++
Raw Normal View History

2012-05-25 07:49:38 -07:00
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main()
{
//This should match any real number
regex number {"((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?((e|E)((\\+|-)?)[[:digit:]]+)?\\b"};
//This should match any word
regex word {"[[:alpha:]]+"};
regex space {"\\s+"};
string input, clean_words, clean_numbers;
//Replace with an empty string
const string format {""};
getline(cin,input);
//Split the input string in numbers and words
clean_numbers=regex_replace(input, number, format);
clean_words=regex_replace(input, word, format);
cout << clean_words << endl;
cout << clean_numbers << endl;
return 0;
}