在re2报头里写着
// C++ interface to the re2 regular-expression library.
// RE2 supports Perl-style regular expressions (with extensions like
// \d, \w, \s, ...).我注意到我的模式失败了,然后注意到\w似乎不起作用。这是我的密码。为什么不起作用?
#include <re2/re2.h>
#include <iostream>
int main(){
RE2::Arg s, i;
std::string sz("a or b");
RE2::Replace(&sz, "\w", "!");
std::cout << sz << std::endl;
}发布于 2014-04-08 04:25:08
正如Johnny在他的评论中提到的那样,您正在将文字\w传递到字符串中,而这可能意味着传递表达式\w。因此,您需要使用\\w来传递表达式。
实际上,在您自己链接的标题中,示例中的字符串中都有\\w。
https://stackoverflow.com/questions/22927462
复制相似问题