Hello htmanning,
Building on NetWallah’s answer: Since you say the URLs in question are “long,” it might be unsafe to assume that the ####.htm pattern (where # is a digit) never appears in the earlier part of a URL. In which case, play safe and anchor the match to the end:
#! perl use strict; use warnings; my $re = qr{ ( \d{4} ) \. htm l? $ }ix; /$re/ && print "$1\n" while <DATA>; __DATA__ http://test-text-ad-1234.html http://test-abc0000.htmdef-ad-5678.HTM test-ghijk-ad-XXXX.html
Output:
12:39 >perl 1616_SoPW.pl 1234 5678 12:39 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Grab 4 numbers from url
by Athanasius
in thread Grab 4 numbers from url
by htmanning
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |