in reply to Regex: plucking numbers from a large string
my @exts;
$largeStr =~ /Tel: 06(\d+)(?{push @exts, $1})/g;
Or the ever handy \G zero-width assertion
Then getting the frequency is just a matter of looping through the keys of %extsmy @exts; push @exts, $1 while $largeStr =~ /\GTel: 06(\d+)/g; # or better yet my %exts; $exts{$1}++ while $largeStr =~ /\GTel: 06(\d+)/g;
print qq[found "$_" $exts{$_} times],$/ for sort keys %exts;
_________
broquaint
update: removed first suggestion as it doesn't seem to work as I expected :-/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regex: plucking numbers from a large string
by Juerd (Abbot) on May 01, 2002 at 19:13 UTC | |
by RMGir (Prior) on May 01, 2002 at 20:12 UTC |