gpt4 book ai didi

c++ - 将正则表达式模式定义为无符号字符

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:55:58 24 4
gpt4 key购买 nike

有什么方法可以创建包含无符号字符的正则表达式模式?我试过:

regex* r = new regex("\\xff");

这会导致异常,指出模式字符超出范围。我还尝试按照正则表达式包含文件中的代码定义我自己的 basic_regex 和我自己的 regex_traits,但这会导致本地包含文件出现奇怪的错误。

如有任何帮助,我们将不胜感激。

最佳答案

这是 ECMAScript 正则表达式中合法的 HexEscapeSequence(这是 C++ 默认使用的),它似乎适用于我的测试:

#include <iostream>
#include <regex>

int main()
{
std::regex re("\\xff");
std::string test = "abc\xff";

std::smatch m;
regex_search(test, m, re);

std::cout << "Found " << m.size() << " match after '"
<< m.prefix() << "'\n";
}

clang++/libc++: Found 1 match after 'abc'

g++/boost.regex (replacing std:: with boost::): Found 1 match after 'abc'

你的实现是什么?

关于c++ - 将正则表达式模式定义为无符号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com