c++ - C++ std::regex 不支持前瞻反向引用
问题描述
我想匹配一个规则,一些名字像ABA一样出现,并且A不能等于B。
例如,“allen_bob_allen”是有效的。'allen_allen_allen' 无效。在https://regexr.com/,我编写了正则表达式模式
([a-z]+)_(?!\1)([a-z]+)_\1
,它运行良好,
但是当我用 C++ 编写这个时,使用 std::regex,
using namespace std;
#include <regex>
int main() {
std::regex regex_test2("([a-z]+)_(?<!\\1)([a-z]+)_\\1");
return 0;
}
我收到以下错误:
libc++abi.dylib: terminating with uncaught exception of type std::__1::regex_error: The expression contained an invalid back reference.
这是我的编译器信息:
解决方案
推荐阅读
- python - 运行 os.system 就好像没有使用 sudo 执行 python
- dart - 我们需要从flutter app icon ontap启动移动设备日历
- r - 为什么调查权重会改变 R SQUARED?
- javascript - 正则表达式单词匹配包含以“ing”结尾的单词但不排除单词anything, something, nothing的文本
- php - PHP 和 Google 的 reCaptcha v2 - 每次都是空响应
- php - 获取符合特定条件的数组的键仅适用于零键
- python-3.x - 仅使用一行代码的 Python 字符串替换(将“H”和“h”替换为“*”)
- javascript - 无法链接到本地目录中的 js 和 css
- javascript - JavaScript 货币转换器
- doctrine-orm - 带有子查询、order by、rand 和 group by 的 Doctrine Query