-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.cpp
More file actions
24 lines (19 loc) · 914 Bytes
/
9.cpp
File metadata and controls
24 lines (19 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <regex>
#include <string>
int main() {
std::string log_line = "~[19640]; 2024-03-13; 20:08:01.038; ERROR; 0; Change log level to DEBUG";
// Регулярное выражение для разбора строки
std::regex log_pattern(R"~(\~#?\[\s*(\d+)\]; (\d{4}-\d{2}-\d{2}); \d{2}:\d{2}:\d{2}\.\d{3}; (TRACE|INFO|DEBUG|WARN|ERROR); \d; (.+))~");
std::smatch match;
if (std::regex_match(log_line, match, log_pattern)) {
std::string number = match[1];
std::string date = match[2];
std::string log_type = match[3];
std::string message = match[4];
std::cout << "Number:" << number << " Date:" << date << " Type:" << log_type << " Message:" << message << std::endl;
} else {
std::cout << "Строка не соответствует ожидаемому формату" << std::endl;
}
return 0;
}