in reply to Grabbing numbers from a URL

You got some good pointers for some one-off code that will likely work just fine for you. None of the answers is particularly robust for real-world URI handling though. So to round it out–

#!/usr/bin/env perl use strictures; use URI; use Path::Tiny; my @uris = map URI->new($_), <DATA>; for my $uri ( @uris ) { if ( $uri =~ /(\d+)\.htm(l)?$/i ) { print "Naive matched -> $uri\n"; } else { print "Naive rejected -> $uri\n"; } my $file = path( $uri->path )->basename; if ( $file =~ /\A[1-9][0-9]{3}\.html?\z/i ) { print "Robust matched -> $uri\n"; } else { print "Robust rejected -> $uri\n"; } print "\n"; } __DATA__ https://moo.cow/queso/1234.HTM https://www.google.com/search?num=100&q=1234.htm http://moo.cow/queso/1234.htm?so=what#taco
Naive matched -> https://moo.cow/queso/1234.HTM Robust matched -> https://moo.cow/queso/1234.HTM Naive matched -> https://www.google.com/search?num=100&q=1234.htm Robust rejected -> https://www.google.com/search?num=100&q=1234.htm Naive rejected -> http://moo.cow/queso/1234.htm?so=what#taco Robust matched -> http://moo.cow/queso/1234.htm?so=what#taco

Update: removed superfluous, silly chomp from code.