有没有办法将不连续的捕获组组合到单个正则表达式中?
Is there a way to combine discontinuous capture groups in a single regex?
我正在使用C++ RE2。我想将串联的不连续捕获组保存在结果字符串中。 正则表达式本身可能有一个或多个捕获组。
RE2::PartialMatch(sourceStr, Regex, &result)
例
sourceStr = "This is an example."
Regex = "(This).*(example)"
result = "Thisexample"
我怎样才能做到这一点?
你可以试试:
string result = sourceStr;
RE2::Replace(&result, "(This).*(example)", "$1$2");
当工作室本身已经存在库时,为什么要使用外部库。将其与"匹配功能"一起使用。 进一步学习的参考链接:https://en.cppreference.com/w/cpp/regex
相关文章:
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 可组合的lambda/std::函数与std::可选
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 混合组合和继承的C++问题
- 将多个 for 循环组合成单个迭代器
- 有没有办法将不连续的捕获组组合到单个正则表达式中?
- 为什么查找 + 插入的组合比单个插入语句工作得更快
- 将8 UINT8_T组合到单个UINTMAX_T中的最快方法是什么?
- 将类成员数组组合到单个数组时性能下降
- DropDownList 组合上的 SendDlgItemMessage CB_GETLBTEXT 返回单个字母
- 如何将字符串和整数组合成单个字符串 (C++)
- 使用C 组合精灵的不同部分在iOS游戏中形成一个单个精灵
- 将任意数量的任意类型的值组合为单个字符串的简单命令
- 是否可以将GSL向量组合成单个向量
- 如何在使用单个测试项目时将所有QtTestLib单元测试的结果组合在一个文件中?
- 组合常量和非常量引用数据成员的单个类
- 将多个函数组合为单个泛型函数
- 使用单个sendmessage选择组合框项
- 在单个可执行文件中组合c#和c++代码