C++ Boost::正则表达式在C++;

C++ Boost::正则表达式在C++;,c++,regex,boost,C++,Regex,Boost,我有这个正则表达式,我想问一下我是否正确使用了它 regex re("(\\S+)=[\"']?((?:.(?![\"']?\\s+(?:\\S+)=|[>\"']))+.)[\"']?",regex::extended,regex::icase); while (getline(input, temp, '>')) { parse+=temp; bool isMatchFound = regex_match(parse,

我有这个正则表达式,我想问一下我是否正确使用了它

regex re("(\\S+)=[\"']?((?:.(?![\"']?\\s+(?:\\S+)=|[>\"']))+.)[\"']?",regex::extended,regex::icase);
       while (getline(input, temp, '>')) {
            parse+=temp;
            bool isMatchFound = regex_match(parse, match, re);

            if(isMatchFound){
            //Do something
            }
        }
它应该匹配
标记,
匹配[2]
应该是
bla.html

它抛出以下异常:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::regex_error> >'
  what():  Invalid preceding regular expression prior to repetition operator.  The error occurred while parsing the regular expression fragment: 'ed_state**>>>HERE>>>, boost::r
terminate在抛出“boost::exception\u detail::clone\u impl”的实例后调用
what():重复运算符之前的前一个正则表达式无效。分析正则表达式片段时出错:“ed_state**>>>此处>>>,boost::r

我不认为extended会减少断言的使用。最好使用Perl模式。
我刚刚用你的选项测试了你的正则表达式,它对我也一样

我会使用这些定义之一(特别是MODs或MODX)。
我使用了MODxs,它在启动时没有抛出错误

 #define MOD    regex_constants::perl | boost::regex::no_mod_s | boost::regex::no_mod_m 
 #define MODx   regex_constants::perl | boost::regex::no_mod_s | boost::regex::no_mod_m | regex_constants::mod_x
 #define MODs   regex_constants::perl | boost::regex::no_mod_m | regex_constants::mod_s
 #define MODxs  regex_constants::perl | boost::regex::no_mod_m | regex_constants::mod_s | regex_constants::mod_x

 #define MODm   regex_constants::perl | boost::regex::no_mod_s  
 #define MODxm  regex_constants::perl | boost::regex::no_mod_s| regex_constants::mod_x
 #define MODsm  regex_constants::perl | regex_constants::mod_s
 #define MODxsm regex_constants::perl | regex_constants::mod_s | regex_constants::mod_x


 boost::regex  rx( "(\\S+)=[\"']?((?:.(?![\"']?\\s+(?:\\S+)=|[>\"']))+.)[\"']?", MODxs );   // or MODs

我会使用regex_搜索<代码>boost::smatch匹配;if(regex_search(parse,match,re){string str1=match[1].str();string str2=match[2].str();}。另外,请使用perl模式而不是extended。@sln perl模式包括icase?或者我应该只使用perl模式和icase吗?您的正则表达式中没有需要区分大小写的内容。我没有将它们包括在我的定义中,因为我总是可以添加
(?I)
根据具体情况将其添加到正则表达式中。查看includes以查找
icase
,然后添加
i
置换(即MODi、MODxi等)。只需将其添加到其中即可。@sln好的,非常感谢