Boost::Regex在C++中的使用
Boost::Regex usage in C++
我得到了这个正则表达式,我想问我是否正确使用了它
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
}
}
它应该匹配<a href="bla.html"></a>
标签,match[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
我不认为extended会因为断言而削减它。最好使用Perl模式
我刚刚用你的选项测试了你的正则表达式,它对我来说也是一样的。
我会使用其中一个定义(特别是MOD或MODxs)
我使用了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
相关文章:
- 此模式的C++RegEx
- C++ std::regex 使用前瞻失败
- std::regex:匹配由数字和空格组成的字符串,并提取数字.如何?
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- 你能防止 std::regex 在无效表达式上抛出异常吗?
- 使用Regex解析cpp中的字符串并创建映射
- C++:如何用split查找单词?Regex
- 在VC2015U3上,std::regex比boost::regex慢得多
- 是否有更有效的方法来生成日期的REGEX字符串
- 在C++中使用带有regex的捕获组
- 将std::regex设置为静态的好主意吗
- 为什么Regex(c++)需要指数时间
- std::regex and dual ABI
- C++11 std::regex后备选项
- 以不同的方式替换每一项,regex c++
- 使用 boost::regex (c++) 比较两个正则表达式
- Build Boost Regex for Windows VS2013
- 包含在 std::regex 搜索中,使用 std::regex_token_iterator 从 std::sub_m
- std::string references、std::regex和boost::filesystem的基本概念
- std::regex 是否保证了最坏情况下的时间复杂度?