我有这样一个字符串:
This is a link [[abcd 1234|xyz 1234]] [[India]] [[abcd 1234|xyz 1234]]
我想得到:
This is a link abcd 1234 [[India]] abcd 1234
我想用双方括号 |并取出之前的东西 |并用整个双方括号替换它,而不是替换任何没有 | 的双方括号使用 Boost 正则表达式。
我们将不胜感激。
最佳答案
只需使用前瞻,(?!pattern)
#include <iostream>
#include <string>
#include <boost/regex.hpp>
int main()
{
std::string str = "This is a link [[abcd 1234|xyz 1234]] [[India]] [[abcd 1234|xyz 1234]]";
boost::regex re("\\[\\[(((?!\\]\\]).)+)\\|.*?]]");
std::cout << boost::regex_replace(str, re, "$1") << '\n';
}
关于c++ - 在 C++ 中使用 Boost 正则表达式进入具有特定特征的方括号之间没有得到答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13934998/