<分区>
寻找类似于 Python 的正则表达式 sub
或 subn
方法的东西。
http://docs.python.org/library/re.html
基本上是这样的 C/C++ api
re.sub(pattern, repl, string, count=0, flags=0)
我可以像在 Python 中那样为 repl
放置一个函数指针。
<分区>
寻找类似于 Python 的正则表达式 sub
或 subn
方法的东西。
http://docs.python.org/library/re.html
基本上是这样的 C/C++ api
re.sub(pattern, repl, string, count=0, flags=0)
我可以像在 Python 中那样为 repl
放置一个函数指针。
最佳答案
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::string text = "Quick brown fox";
std::regex vowel_re("a|o|e|u|i");
std::cout << std::regex_replace(text, vowel_re, "[$&]") << '\n';
}
输出:
Q[u][i]ck br[o]wn f[o]x
关于具有函数指针替换的 C++ 正则表达式库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12654232/