Reputation: 33
I want to replace everything in a line except for alphabets, numbers and periods with whitespaces in c++.
Could anyone please give me a regex in c++ that I can use ?
I was using [^[:alnum:]]
till now but that works only for alpha and numeric.
Thank you !
Upvotes: 0
Views: 262
Reputation: 76315
std::replace_if(line.begin(), line.end(),
[](char ch){ return !isalnum(ch) && ch != '.'; }, ' ');
No need to argue about escapes.
Upvotes: 2
Reputation: 521437
I'm not a C++ person, but you can try adding dots to the regex:
[^[:alnum:].]
An alternative:
[^a-zA-Z0-9.]
Upvotes: 2