difference_type length() const;
概要
マッチした文字列の長さを返す。
戻り値
matched ? distance(first, second) : 0
例
#include <iostream>
#include <regex>
#include <string>
int main()
{
const std::string s("123");
const std::regex re(R"(\d+)");
std::smatch m;
if (std::regex_search(s, m, re)) {
std::ssub_match sub = m[0];
if (sub.matched) {
std::cout << sub.length() << std::endl;
sub.matched = false;
std::cout << sub.length() << std::endl;
} else {
std::cout << "not participate" << std::endl;
}
} else {
std::cout << "not match" << std::endl;
}
}
xxxxxxxxxx
#include <iostream>
#include <regex>
#include <string>
int main()
{
const std::string s("123");
const std::regex re(R"(\d+)");
std::smatch m;
if (std::regex_search(s, m, re)) {
std::ssub_match sub = m[0];
if (sub.matched) {
std::cout << sub.length() << std::endl;
sub.matched = false;
std::cout << sub.length() << std::endl;
} else {
std::cout << "not participate" << std::endl;
}
} else {
std::cout << "not match" << std::endl;
}
}
出力
3
0
バージョン
言語
- C++11
処理系
- Clang: 3.0 ✅, 3.1 ✅, 3.2 ✅, 3.3 ✅, 3.4 ✅, 3.5 ✅, 3.6 ✅
- GCC: 4.9.0 ✅, 4.9.1 ✅, 5.0.0 ✅
- ICC: ??
- Visual C++: ??