Boost.Regex 奇怪之处

发布于 2024-08-07 18:11:40 字数 254 浏览 3 评论 0原文

有谁知道为什么下面的代码会输出“不匹配”?

  boost::regex r(".*\\.");
  std::string s("app.test");
  if (boost::regex_match(s, r))
    std::cout << "match" << std::endl;
  else
    std::cout << "no match" << std::endl;

Does anyone have any idea why the following code would output "no match"?

  boost::regex r(".*\\.");
  std::string s("app.test");
  if (boost::regex_match(s, r))
    std::cout << "match" << std::endl;
  else
    std::cout << "no match" << std::endl;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2024-08-14 18:11:40

我相信 regex_match() 匹配整个字符串。请尝试使用 regex_search()

它将与以下正则表达式:

boost::regex r(".*\\..*");

regex_match() 函数一起使用。但同样,regex_search() 可能就是您正在寻找的。

I believe regex_match() matches against the entire string. Try regex_search() instead.

It would have worked with the following regex:

boost::regex r(".*\\..*");

and the regex_match() function. But again, regex_search() is what you're probably looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文