This will depend a lot on how you define each format -- exactly what qualifies as an apartment number, and what qualifies as a phone number? Some apartment numbers have letters, for instance: Apt. #54a. But from your description, it sounds like you want to catch things like Apt. 302, but not 302-4321. In that case, you could grab all 3-4 digit strings that are not preceded or followed by a dash:
#!/usr/bin/env perl use 5.010; use strict; use warnings; my $field = 'Apt.302. 123-4567. 4021'; # from database record $field = " $field "; # pad it while($field =~ /[^\d-](\d\d\d\d?)[^\d-]/g){ say "Apartment: $1"; }
I'd guess for real-life data, you'll have to get fancier than that, but that may get you headed in the right direction.
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
In reply to Re: Pull 3-digit and 4-digit numbers from string
by aaron_baugher
in thread Pull 3-digit and 4-digit numbers from string
by htmanning
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |