Here's another approach:
Add the /i modifier if you want case insensitive matching:c:\@Work\Perl\monks>perl -wMstrict -le "print qq{perl version $]}; ;; my @strings = ( 'Link:1625 housing Link:2004', 'Link:638 92-5000|Link:63892-5070', ); ;; my $rx_numeric = qr{ \d+ (?: - \d+)? }xms; ;; for my $str (@strings) { my @matches = $str =~ m{ Link : ($rx_numeric (?: \s+ $rx_numeric)?) + }xmsg; print qq{'$str' -> }, map qq{'$_' }, @matches; } " perl version 5.008009 'Link:1625 housing Link:2004' -> '1625' '2004' 'Link:638 92-5000|Link:63892-5070' -> '638 92-5000' '63892-5070'
Update: I often find it prudent to add an extra element of safety by using boundary assertions in data field regexes. So $rx_numeric might be better defined as (tested)
my $rx_numeric = qr{ (?<! \d) \d+ (?: - \d+)? (?! \d) }xms;
See (?<!pattern) (?!pattern) in Extended Patterns in perlre.
Give a man a fish: <%-{-{-{-<
In reply to Re: Perl Regex
by AnomalousMonk
in thread Perl Regex
by audioboxer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |