【发布时间】:2021-01-07 22:20:33
【问题描述】:
我注意到字符类[:blank:] 也匹配\v,如下面的代码所示。不过,那个shouldn't be there, per POSIX,应该吗?
#include <string>
#include <iostream>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
int main() {
std::string const text{"\v"};
cout << (sregex_token_iterator{text.begin(), text.end(), regex{R"((?-m)^([[:blank:]])$)"}} != sregex_token_iterator{});
cout << (sregex_token_iterator{text.begin(), text.end(), regex{R"((?-m)^([ \t])$)"}} != sregex_token_iterator{}) << '\n';
// output: 10, but I expected 00
return 0;
}
显然,由于this page of Boost 没有提及我看到列出的here 的所有字符类,我怀疑Boost 正则表达式不符合POSIX,即使它们使用一些那些命名的字符类。嗯,连 POSIX 这个词都没有出现在那个 Boost 页面上,所以我想我几乎是在回答自己,但我觉得不够自信。
我还没有检查过这些字符中的哪一个属于[:blank:] 和/或[:space:],但我猜这里可能还会有其他惊喜:
const auto LF = "\x0A";
const auto VT = "\x0B";
const auto FF = "\x0C";
const auto CR = "\x0D";
const auto CRLF = "\x0D\x0A";
const auto NEL = "\xC2\x85";
const auto LS = "\xE2\x80\xA8";
const auto PS = "\xE2\x80\xA9";
【问题讨论】:
标签: c++ regex boost posix line-breaks