繁体   English   中英

RE2 不匹配非 ASCII 字符

[英]RE2 Not matching non-ascii characters

我无法让 RE2 使用它们的十六进制/八进制表示来匹配字节(不是 ascii)。

下面的代码片段解释了这个问题:

char *test = "abc""\xe2""xyz";
std::string str(test); // "abc\342xyz" . \342 is octal for \xe2
// str.size() == 7

re2::StringPiece string_piece(str); // size is 7, as expected

std::string out;

// extracts the letter 'z' into 'out;. \172 is the octal for z
bool match = re2::RE2::PartialMatch(string_piece, ("(\172)"), &out); // match = true, out = 'z'.

// should extract the character \342...but it doesn't.
match = re2::RE2::PartialMatch(string_piece, ("(\342)"), &out); // match = false

将编码设置为 latin-1 - RE2 默认为 UTF-8

match = re2::RE2::PartialMatch(string_piece,
          re2::RE2("(\342)", re2::RE2::Latin1),
          &out);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM