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 @@
#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;
}