google / re2

RE2 is a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python. It is a C++ library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to regex parentheses

jiapengwen opened this issue · comments

show you my code; re2 version = 2023-07-01 release

  RE2 re(R"(\(foo\))");
  std::string word1;
  std::string word2;
  std::string word3;
  bool ret = RE2::PartialMatch("(foo)", re, &word1, &word2, &word3);
  std::cout << ret << std::endl;
  std::cout << word1 << std::endl;
  std::cout << word2 << std::endl;
  std::cout << word3 << std::endl;

result

0


re contains zero capturing groups whereas the RE2::PartialMatch() call expects three capturing groups, so the call fails; RE2::PartialMatch("(foo)", re); would succeed.