如何在与提升正则表达式匹配的字符串中找到索引
How can I find the index in a string that matches a boost regex?
如何在与提升正则表达式匹配的字符串中找到索引?
使用 match_results
的 position
成员函数:
int find_match_offset(std::string const& string_to_search,
boost::regex const& expression)
{
boost::smatch results;
if(boost::regex_match(string_to_search,results,expression))
{
return results.position()
}
return -1;
}
如果使用 boost::regex_match则匹配的是整个字符串。
也许你的意思是使用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;
}
}
相关文章:
- 按字母顺序对C++问题中的子字符串索引进行分区
- C++ 中字符串向量的索引
- C++ - 成功打印超出范围的字符串索引
- 对于循环增量器不能用作字符串向量的索引
- 如何检索由带通配符的字符串索引的对象
- 访问包含P的有效索引时返回空格的C++字符串
- 在我的 for 循环中,如何将索引更改为字符串?
- 有效地从文本文件中读取带有字符串索引的大型二维数组(矩阵)
- 如何使用调整后的字符串索引第二次通过循环运行字符串
- C++中的字符串索引问题
- Qt5.5 Q奇数结果的字符串索引
- 是否有理由使用字符串 => 索引到向量的映射,而不是字符串 => 对象?
- 在数组 C++ 中搜索字符串索引
- C++:字符串索引和保留标点符号时出现问题
- C++中类似python的字符串索引
- 如何在c++中高效地实现PHP字符串索引数组
- 如果访问了错误的字符串索引,c++不会抛出错误
- C++中的 Unicode 字符串索引
- 如何按索引为 c++ 字符串索引赋值
- 在 C++ 中使用字符串索引的整数