in reply to Grabbing numbers from a URL
You have to decide about something-12341234.html. The code above captures 12341234 which is usually what is desired. Do you really only want to have 41234, 5 digits in that situation? I suspect not.#!/usr/bin/perl use strict; use warnings; foreach my $url ("abgc100.html", "xyz1000.htMl", "qwer10.html", "abc123.htm", "qrz12345.htm", "something-12341234.html") { my ($number) = $url =~ /(\d+)\.htm(l)?$/i; print "$number\n"; } __END__ 100 1000 10 123 12345 12341234
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Grabbing numbers from a URL
by BillKSmith (Monsignor) on Jul 09, 2017 at 13:20 UTC | |
by Marshall (Canon) on Jul 09, 2017 at 13:56 UTC | |
|
Re^2: Grabbing numbers from a URL
by htmanning (Friar) on Jul 09, 2017 at 06:43 UTC |