match all printable basic ASCII characters in c++
#include <iostream>
#include <sys/types.h>
#include <regex.h>
using namespace std;
#define STR "QWERTYUIOPASDFGHJKLZXCVBNM"
//#define STR "qwertyuiopasdfghjklzxcvbnm123456789"
//#define STR "`~!@#$%^&*()-_+={[}]|\\;:i\"'<,>.?/"
#define PATTERN "^([ -~]{8,})$" //匹配所有的可以输入的ascii码
int main()
{
cout << ' ' << int(' ') << endl;
cout << '~' << int('~') << endl;
cout << STR <<endl;
cout << PATTERN << endl;
regex_t regex;
if(regcomp(®ex, PATTERN, REG_EXTENDED) == 0) {
if(regexec(®ex, STR, 0, NULL, 0) == 0) {
cout << "match reg-exp" << endl;
} else {
cout << "doesn't match reg-exp" << endl;
}
} else {
cout << "reg-exp compilation error" << endl;
}
return 0;
}