Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;正则表达式匹配连续标志不';不匹配起始子字符串_C++_Regex - Fatal编程技术网

C++ C++;正则表达式匹配连续标志不';不匹配起始子字符串

C++ C++;正则表达式匹配连续标志不';不匹配起始子字符串,c++,regex,C++,Regex,我一直在用下面的例子来解释regex_match string text("* @file my_file.c"); regex exp("\\s*\\*\\s*@file") if(regex_match(text,exp,regex_constants::match_continuous)) //This doesn't work 我知道regex_match试图用regex表达式匹配整个文本,但据我所知,match_continuous标志应该接受从文本开头开始的子字符串。

我一直在用下面的例子来解释regex_match

string text("*  @file  my_file.c");
regex exp("\\s*\\*\\s*@file")

if(regex_match(text,exp,regex_constants::match_continuous))
    //This doesn't work
我知道regex_match试图用regex表达式匹配整个文本,但据我所知,match_continuous标志应该接受从文本开头开始的子字符串。但是我的运气不好,所以我不得不把我的解决方案转换成这个

string text("*  @file  my_file.c");
regex exp("^\\s*\\*\\s*@file")

if(regex_search(text,exp))
    //This time works

我想问一下,在第一个例子中,我做错了什么。我的环境是VS2010。

match\u continuous
regex\u search
配合使用

例如


这可能是个bug,我记得一两年前看到过类似的东西。所以使用regex_常量::match_continuous似乎是正确的,不是吗?我想我可能遗漏了什么。我想是的,但我不确定,所以我不会把它作为一个答案。我可能也遗漏了什么。
match\u continuous
不会改变这样一个事实,即整个序列必须匹配表达式才能成功。该标准明确要求
m.suffix
作为
regex\u match
调用的后置条件为空范围(其中
m
是一个
match\u results
实例,在您的案例中暗示)。据我所知,
match\u continuous
在与
regex\u match
一起使用时是毫无意义和冗余的。您是说它被保留在那里是为了与regex\u常量::match\u flag\u类型兼容,以防止出现第二个标志域?
std::regex_search(text, exp, std::regex_constants::match_continuous)