C STD Regexp为什么不匹配
c++ std regexp why not matched?
i wannna获取关键字匹配长度
但是,始终匹配计数为零
为什么..?
string text = "sp_call('%1','%2','%a');";
std::regex regexp("%[0-9]");
std::smatch m;
std::regex_match(text, m, regexp);
int length = m.size();
cout << text.c_str() << " matched " << length << endl; // always 0
regex_match
确定正则表达式E是否匹配整个目标字符序列,该序列可以指定为std :: string,c-string或Iterator对。
您需要使用regex_search
确定正则表达E与目标字符序列中的某些子序列之间是否有匹配。
您也可以使用regex_iterator
,此处的示例:
string text = "sp_call('%1','%2','%a');";
std::regex regexp("%[0-9]");
auto words_begin =
std::sregex_iterator(text.begin(), text.end(), regexp);
auto words_end = std::sregex_iterator();
std::cout << "Found "
<< std::distance(words_begin, words_end)
<< " words:n";
for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
std::smatch match = *i;
std::string match_str = match.str();
std::cout << match_str << 'n';
}
找到了2个单词:
%1
%2
相关文章:
- 为什么我收到错误:"运算符<<不匹配?
- 模板推导:为什么函数指针模板定义在常量和/或引用时不匹配?
- 为什么我的数组值与此处的全局变量不匹配?
- 为什么使用不匹配的参数调用重载函数仍然有效
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- 为什么一次包装 typedef 函数签名与原始签名不匹配
- 作为模板类型参数,为什么 type[N] 与其专用版本不匹配----模板<类 T>类 S<T[]>
- 如果在开关情况下不匹配,为什么此函数返回 ASCII 值?
- C STD Regexp为什么不匹配
- 为什么这个"uint64_t"模板专用化与 Mac 平台上的"无符号长"不匹配?
- 不匹配新[]和删除,为什么没有内存泄漏
- 为什么在使用"std::find"时,错误与"运算符=="不匹配?
- 为什么此代码编译 (C++11) 而没有类型不匹配错误
- 为什么regex_match与我的正则表达式不匹配
- Curly Braces构造函数更喜欢initializer_list而不是更好的匹配.为什么
- 为什么构造函数的数量与Destructor调用的数量不匹配
- 为什么我们有一个类型不匹配
- 为什么在列表initialization函数参数时,显式构造函数不匹配
- 为什么我没有警告枚举比较不匹配
- 为什么迭代器类型与矢量容器中的 value_type * 不匹配