I am trying to remove the non-printable characters using std::regex and [:print:] character class.
The input string could be like this
"\nTesting\t regex and \n\n\t printable characters \a\b set \0\f"
Here \n, \t, \a, \b, \0, \f are non printable characters. I want to remove non-printable except \n and \t.
std::regex nonprintable_regex("(^[[:print:]]+)");
std::smatch sm;
if (std::regex_search(str, sm, nonprintable_regex)) {
str = std::regex_replace(str, nonprintable_regex, "");
}
But I am not getting the expected result.
"\nTesting\t regex and \n\n\t printable characters set "
I know I have to add something for \n and \t, but no idea how to add that condition. Any pointers/help, Thanks