0

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;
}
4

1 回答 1

1

正如约翰尼莫普在他的评论中提到的那样\w,当您可能打算传入表达式时,您正在将文字传递到字符串中\w。因此,您需要使用\\w来传递表达式。

实际上,在您自己链接的标题中,示例都包含\\w在字符串中。

于 2014-04-08T04:25:08.607 回答