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