in reply to How can I combine these two regular expressions?

Your requirements are not crystal clear to me. I see that your original program (turned into a Short, Self-Contained, Correct Example):

use strict; use warnings; use Data::Dumper; my $path = '/.snapshots123/yabsm/root/hourly/day=2021_03_04,time=21:20 +'; my $end_of_path; $end_of_path = $1 if $path =~ m/([^\/]+$)/; my @nums = $end_of_path =~ m/([0-9]{2,4})/g; print Dumper( \@nums );
prints:
$VAR1 = [ '2021', '03', '04', '21', '20' ];

... as does my simpler version:

use strict; use warnings; use Data::Dumper; my $path = '/.snapshots123/yabsm/root/hourly/day=2021_03_04,time=21:20 +'; my @nums = $path =~ m{/day=(\d\d\d\d)_(\d\d)_(\d\d),time=(\d\d):(\d\d) +$}; print Dumper( \@nums );
Does my version satisfy your requirements?

Replies are listed 'Best First'.
Re^2: How can I combine these two regular expressions?
by thirtySeven (Acolyte) on Mar 05, 2021 at 14:17 UTC
    Thanks this is great because its so simple.