通用符号'\\ p {S}'没有'匹配'使用boost wregex [英] Common symbols '\p{S}' not been 'matched' using boost wregex
问题描述
我使用的是code以下尝试和使用正则表达式匹配的符号,(作为一个例子,我想匹配圈星号,的 http://graphemica.com/%E2%9C%AA )
I am using the code below to try and match symbols using regex, (as an example, I am trying to match the circle star symbol, 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;
}
//...
文本
的字节值 {97,10026,99}
,(或`{0x61,0x272A ,0x63}')。
所以它是一个有效符号
The byte value of text
is {97, 10026, 99}
, (or `{0x61,0x272A, 0x63}').
So it is a valid symbol.
在code中的两个字母相匹配,'A'
0x61
和 c'``0x63
,但不是符号✪
( 0x272A
)。
我曾与几个其他的符号,其中没有工作,(©为例)试了一下。
The code matches the 2 letters, 'a'
0x61
and 'c'``0x63
, but not the symbol ✪
(0x272A
).
I have tried it with a couple of other symbols and none of them work, (© for example).
我是什么在这里失踪?
推荐答案
在Boost.Regex文件明确指出的有统一为$ C $特定的C字符类不支持使用时 的boost :: wregex
The Boost.Regex documentation explicitly states that there's no support for Unicode-specific character classes when using boost::wregex
.
如果你想要这个功能,你需要<一个href=\"http://www.boost.org/libs/regex/doc/html/boost_regex/install.html#boost_regex.install.building_with_uni$c$c_and_icu_su\"相对=nofollow>与ICU支持启用然后使用的boost :: u32regex
类型,而不是升压建立Boost.Regex :: wregex
。
If you want this functionality, you'll need to build Boost.Regex with ICU support enabled then use the boost::u32regex
type instead of boost::wregex
.
这篇关于通用符号'\\ p {S}'没有'匹配'使用boost wregex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!