最終更新日時(UTC):
が更新

履歴 編集

function
<regex>

std::sub_match::length(C++11)

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;
  }
}

出力

3
0

バージョン

言語

  • C++11

処理系