use strict;
my $str = 'http://localhost/
http://localhost/packages/a/
http://localhost/packages/b/
http://localhost/packages/c/
http://localhost/packages/core/
http://localhost/packages/d/
http://localhost/packages/e/
http://localhost/packages/f/
http://localhost/packages/g/
http://localhost/packages/h/
http://localhost/packages/i/
http://localhost/packages/j/
http://localhost/packages/k/
http://localhost/packages/l/
http://localhost/packages/m/
http://localhost/packages/meta/
http://localhost/packages/n/
http://localhost/packages/o/
http://localhost/packages/p/
http://localhost/packages/q/
http://localhost/packages/r/
http://localhost/packages/s/
http://localhost/packages/t/
http://localhost/packages/u/
http://localhost/packages/v/
http://localhost/packages/w/
http://localhost/packages/x/
http://localhost/packages/y/
http://localhost/packages/z/
http://localhost/packages/a/atkmm-2.28.2-2-x86_64.chi.zst
http://localhost/packages/a/atom-1.61.0beta0-2-x86_64.chi.zst
http://localhost/packages/a/atril-1.26.0-1-x86_64.chi.zst
http://localhost/packages/a/attica-5.94.0-1-x86_64.chi.zst
http://localhost/packages/a/attr-2.5.1-2-x86_64.chi.zst
http://localhost/packages/a/aubio-0.4.9-13-x86_64.chi.zst
http://localhost/packages/a/aubio-0.4.9-7-x86_64.chi.zst
http://localhost/packages/a/audacious-4.0.5-1-x86_64.chi.zst
http://localhost/packages/a/audacious-plugins-4.0.5-1-x86_64.chi.zst
http://localhost/packages/a/audacity-1:2.4.1-7-x86_64.chi.zst
http://localhost/packages/a/audiofile-0.3.6-6-x86_64.chi.zst
http://localhost/packages/a/audit-3.0.8-1-x86_64.chi.zst
http://localhost/packages/a/augeas-1.12.0-2-x86_64.chi.zst
http://localhost/packages/a/auracle-git-r366.8739929-4-x86_64.chi.zst
';
my $regex = qr/(?!.*\/)(.*)-(([^-]+)-([0-9]+))-([^.]+)(\.chi\.zst)/p;
if ( $str =~ /$regex/ ) {
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