414行目: 414行目:
     try {
     try {
       logFileAnalysis();
       logFileAnalysis();
    }
    catch (const std::exception &e) {
      std::cerr << "Main function error: " << e.what() << std::endl;
      return -1;
    }
    return 0;
}
</syntaxhighlight>
<br><br>
== 正規表現の使用例 : 日付形式の変換 ==
以下の例では、regex_replaceメソッドを使用して日付形式を変更している。<br>
<br>
<syntaxhighlight lang="c++">
#include <iostream>
#include <regex>
#include <string>
void textReplacement()
{
    try {
      std::string text = "The date is 2023/12/25 and 2024/01/01";
      std::regex pattern(R"((\d{4})/(\d{2})/(\d{2}))");
      std::string result = std::regex_replace(text, pattern, "$3-$2-$1");
      std::cout << "Transformed: " << result << std::endl;
      // 置換が行われたか確認
      if (result == text) {
          std::cerr << "Warning: No dates were transformed" << std::endl;
      }
    }
    catch (const std::regex_error &e) {
      std::cerr << "Regex error in date transformation: " << e.what() << std::endl;
      std::cerr << "Code: " << e.code() << std::endl;
    }
    catch (const std::exception &e) {
      std::cerr << "Error in date transformation: " << e.what() << std::endl;
    }
}
int main()
{
    try {
      textReplacement();
     }
     }
     catch (const std::exception &e) {
     catch (const std::exception &e) {