[英]combining regex in c++
I want to replace everything in a line except for alphabets, numbers and periods with whitespaces in c++. 我想用C ++中的空格替换一行中的所有内容,除了字母,数字和句点。
Could anyone please give me a regex in c++ that I can use ? 谁能给我我可以使用的C ++正则表达式?
I was using [^[:alnum:]]
till now but that works only for alpha and numeric. [^[:alnum:]]
我一直使用[^[:alnum:]]
,但仅适用于字母和数字。
Thank you ! 谢谢 !
I'm not a C++ person, but you can try adding dots to the regex: 我不是C ++人,但是您可以尝试在正则表达式中添加点:
[^[:alnum:].]
An alternative: 替代:
[^a-zA-Z0-9.]
std::replace_if(line.begin(), line.end(),
[](char ch){ return !isalnum(ch) && ch != '.'; }, ' ');
No need to argue about escapes. 无需争论逃脱。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.