Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.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/16.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++ 是我错了,还是这是Visual Studio 2013正则表达式错误?_C++_Regex_Visual C++_C++11_Gcc - Fatal编程技术网

C++ 是我错了,还是这是Visual Studio 2013正则表达式错误?

C++ 是我错了,还是这是Visual Studio 2013正则表达式错误?,c++,regex,visual-c++,c++11,gcc,C++,Regex,Visual C++,C++11,Gcc,我有一个正则表达式,可以从HTML页面中删除额外的vml标记 std::string regstr = R"(<!\[if !vml\]>([\s\S]*?)<!\[endif\]>)"; std::regex regex(regstr, std::regex_constants::ECMAScript); std::smatch mr; std::string str = R"(</v:shape><![endif]--

我有一个正则表达式,可以从HTML页面中删除额外的vml标记

    std::string regstr = R"(<!\[if !vml\]>([\s\S]*?)<!\[endif\]>)";
    std::regex regex(regstr, std::regex_constants::ECMAScript);
    std::smatch mr;
    std::string str = R"(</v:shape><![endif]--><![if !vml]>
<img width=234 height=383 src="file:///C:\Users\jcyangzh\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png" v:shapes="110x110">
<![endif]></span></span><span lang=EN-US><o:p></o:p></span></p>)";
    if (std::regex_search(str, mr, regex)) {
        std::cout << "match found: " << mr.size() << "\n";
        for (size_t i = 0; i < mr.size(); ++i) {
            std::string strrep = mr.str(i);
            std::cout << "index: " << i << "\n string: " << strrep << "\n\n";
        }
    }
对于GNU GCC编译器4.9.2最新tdm GCC Windows端口,上述代码有效。我使用的正则表达式不匹配

但是对于VisualStudio2013更新4,正则表达式不起作用,并且std::regex_搜索返回false

如果将密钥模式[\s\s]替换为\s |\s,则将有3个匹配项


[\s\s]是有效的C++11 Ecma正则表达式还是VS2013更新4的错误?

[\s\s]是有效的ECMAScript正则表达式。看到“转义字符”项目符号了吗?每个人都应该知道你不能使用正则表达式解析HTML。@小狗:当然,是的,但有时你不需要为了一个小任务而拉出800磅的大猩猩。如果OP想要使用regex,并且它在他的用例中工作,那么就没有必要白费力气。我使用,它会显示正确的结果:但是根据博客,在线编译器是一个开发分支,所以它可能与您拥有的不同,如果您包含一个main和include语句,那么我就可以复制、粘贴您的代码并进行测试,而不必将它们放在我自己的代码中。这是一个很小但很好的一部分,提供了一个。无论如何,Clang3.5产生的结果与gcc相同,所以我猜这是VC++中的一个bug。