gpt4 book ai didi

c++ - 表达式包含不匹配的括号

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:41 25 4
gpt4 key购买 nike

我的程序给我一条错误消息:libc++abi.dylib: terminating with uncaught exception of type std::__1::regex_error: The expression contained mismatched ( and ) 我可以'不知道如何修复它。括号是什么?

#include <regex>
#include <iostream>
#include <string>
using namespace std;
using namespace regex_constants;

int main() {
// here can be url, or hashtag or split string:
// www.example.com or #followback or currentratesoughttogodown and output must be example or followback or currentratesoughttogodown.
string input = "www.example.com";
smatch m;
regex_match ( input, m, regex ("(?<=www.|\\#)(\\w+)(?=\\.)?") );

return 0;
}

我用gcc编译:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

最佳答案

C++11 uses ECMAScript's (ECMA-262) regex syntax, so it will not have look-behind (other flavors of regex that C++11 supports also doesn't have look-behind).

Lookahead(?=)虽然支持

你或许可以试试 (?:www\\.|\\#)(\\w+)(?=\\.)

虽然捕获第 1 组。或者你可以看看使用 Boost.RegexBoost.Xpressive支持 lookbehind .

关于c++ - 表达式包含不匹配的括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29001933/

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