How can I match a string only to Chinese letters using regex?

I want to get a regular expression that can match a string consisting of a Chinese character and without English or any other character. [\ u4e00- \ u9fa5] does not work at all, and [^ x00-xff] will correspond to the situation with the accent symbol or another language.

boost::wregex reg(L"\\w*"); bool b = boost::regex_match(L"我a", reg); // expected to be false b = boost::regex_match(L"我,", reg); // expected to be false b = boost::regex_match(L"我", reg); // expected to be true 
+6
source share
2 answers

The following regex works fine.

 boost::wregex reg(L"^[\u4e00-\u9fa5]+"); 
0
source

Boost with ICU can use character classes . I think you are looking for a \p{Han} script. Alternatively, U + 4E00..U + 9FFF is \p{InCJK_Unified_Ideographs}

+2
source

All Articles