in reply to Grab 4 numbers from url
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, |
|
|---|