use strict;
my $str = '04.08.2024 06:41:14.775 Получено время 2447 Название устройства №2 04.08.2024 6:41:15 - синхронизация не требуется
04.08.2024 06:43:14.786 Получено время 22B3 Название устройства №3 04.08.2024 6:43:16 - время получения ответа превышает допуск
04.08.2024 11:47:01.967 Истекли попытки отправить запрос 234C Название устройства №4
05.08.2024 14:03:55.149 Получено время 2356 Название устройства №1 05.08.2024 14:03:57 - время получения ответа превышает допуск
05.08.2024 14:03:56.796 Получено время 2356 Название устройства №1 05.08.2024 14:03:58 - требуется синхронизация
05.08.2024 14:03:58.920 Установлена коррекция времени 2356 Название устройства №1';
my $regex = qr/^(?<date>\d{2}\.\d{2}\.\d{4})\s(?<time>\d{2}:\d{2}:\d{2}\.\d{3})\s{2}(?<msg>.+?(?=\s\d))\s(?<id>.{4})\s(?<name>.+?(?=$|\d{2}\.))(?<comment>.*$)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html