常用符号 '\p{S}' 未 'matched' 使用 boost wregex
Common symbols '\p{S}' not been 'matched' using boost wregex
我正在使用下面的代码尝试使用正则表达式匹配符号,(例如,我正在尝试匹配圆星符号,http://graphemica.com/%E2%9C%AA)
#include <boost/regex.hpp>
//...
std::wstring text = L"a✪c";
auto re = L"(\p{S}|\p{L})+?";
boost::wregex r(re);
boost::regex_token_iterator<std::wstring::const_iterator>
i(boost::make_regex_token_iterator(text, r, 1)), j;
while (i != j)
{
std::wstring x = *i;
++i;
}
//...
text
的字节值为{97, 10026, 99}
,(或`{0x61,0x272A, 0x63}')。
所以它是一个有效的符号。
代码匹配 2 个字母,'a'
0x61
和 'c'``0x63
,但不匹配符号 ✪
(0x272A
)。
我已经用其他几个符号尝试过它并且 none 其中的工作,(例如©)。
我在这里错过了什么?
Boost.Regex 文档明确指出 there's no support for Unicode-specific character classes 使用 boost::wregex
.
如果您需要此功能,您需要 build Boost.Regex with ICU support 启用,然后使用 boost::u32regex
类型而不是 boost::wregex
。
我正在使用下面的代码尝试使用正则表达式匹配符号,(例如,我正在尝试匹配圆星符号,http://graphemica.com/%E2%9C%AA)
#include <boost/regex.hpp>
//...
std::wstring text = L"a✪c";
auto re = L"(\p{S}|\p{L})+?";
boost::wregex r(re);
boost::regex_token_iterator<std::wstring::const_iterator>
i(boost::make_regex_token_iterator(text, r, 1)), j;
while (i != j)
{
std::wstring x = *i;
++i;
}
//...
text
的字节值为{97, 10026, 99}
,(或`{0x61,0x272A, 0x63}')。
所以它是一个有效的符号。
代码匹配 2 个字母,'a'
0x61
和 'c'``0x63
,但不匹配符号 ✪
(0x272A
)。
我已经用其他几个符号尝试过它并且 none 其中的工作,(例如©)。
我在这里错过了什么?
Boost.Regex 文档明确指出 there's no support for Unicode-specific character classes 使用 boost::wregex
.
如果您需要此功能,您需要 build Boost.Regex with ICU support 启用,然后使用 boost::u32regex
类型而不是 boost::wregex
。