如何在匹配boost正则表达式的字符串中找到索引? [英] How can I find the index in a string that matches a boost regex?
本文介绍了如何在匹配boost正则表达式的字符串中找到索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在匹配boost正则表达式的字符串中找到索引?
How can I find the index in a string that matches a boost regex?
推荐答案
如果使用boost :: regex_match它是匹配的整个字符串。
也许你的意思是使用regex_search:
If you use boost::regex_match it's the whole string that's matching.
Maybe you mean to use regex_search:
void index(boost::regex& re,const std::string& input){
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
std::string::const_iterator s = input.begin();
std::string::const_iterator e = input.end();
while (boost::regex_search(s,e,what,re,flags)){
std::cout << what.position() << std::endl;
std::string::difference_type l = what.length();
std::string::difference_type p = what.position();
s += p + l;
}
}
这篇关于如何在匹配boost正则表达式的字符串中找到索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文