简单的regex_match在VS 2012不工作 [英] simple regex_match in VS 2012 not working

查看:178
本文介绍了简单的regex_match在VS 2012不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS 2012 C ++。以下简单的regex_match找不到我要找的。我已经剥离了下面的。我缺少什么?

I'm using VS 2012 C++. The following simple regex_match doesn't ever find what I'm looking for. I've stripped it down to the following. What am I missing?

#include <string>
#include <regex>
using namespace std;

int _tmain( int argc, char *argv[] )
{
   int i = 0;
   auto matches = smatch();
   regex rx( "." );
   string haystack( "ABC." );

   if( regex_match( haystack, matches, rx ) )
      i++;
   if( regex_match( haystack, rx ) )
      i++;
   if( regex_match( haystack.begin(), haystack.end(), rx ) )
      i++;
}

regex_match false。

推荐答案

您应该使用 regex_search


请注意,regex_match只会成功匹配常规
表达式到整个字符序列,而std :: regex_search
将成功匹配子序列。

Note that regex_match will only successfully match a regular expression to an entire character sequence, whereas std::regex_search will successfully match subsequences.

匹配项:

if( regex_search( haystack, matches, rx ) )
   i++;
if( regex_search( haystack, rx ) )
   i++;
if( regex_search( haystack.begin(), haystack.end(), rx ) )
   i++;

这篇关于简单的regex_match在VS 2012不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆