use strict;
my $str = '[BEGIN TYPESCRIPT]
[H[JLinux dcim-mao 4.19.0-20-cloud-amd64 #1 SMP Debian 4.19.235-1 (2022-03-17) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Jul 10 08:00:55 2023 from 172.17.0.2
[?2004hroot@dcim-mao:~# cd
[?2004l
[?2004hroot@dcim-mao:~# ls
[?2004l
[?2004hroot@dcim-mao:~# cd /
[?2004l
[?2004hroot@dcim-mao:/# ls
[?2004l
app etc media public srv usr
bin home mnt root supervisor.conf var
boot lib opt run sys
dev lib64 proc sbin tmp
[?2004hroot@dcim-mao:/#
[END TYPESCRIPT]';
my $regex = qr/[^[:print:]]\[[^a-zA-Z]*[a-zA-Z]/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