regular expressions - counting matches

I have an expression along the lines of:

/KEYWORD([A|B]\d.+?)/\1/g;

is there simple way to get a list of all the [A|B]\d. that matched and how many times each one was encountered?

thanks
_D_Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
andreifConnect With a Mentor Commented:
Try this:

map {$hash{$_}++} ($String =~ /KEYWORD([A|B]\d.+?)/g);

# as a result you get hash with matches as keys and number
# as value. That number shows how many times this match
# encountered.

# I'll print this hash for example

foreach (keys %hash) {
     print "$_: $hash{$_}\n";
}
0
 
ozoCommented:
@list = /KEYWORD([A|B]\d.+?)/g
0
 
ozoCommented:
$howmanytimes = s/KEYWORD([A|B]\d.+?)/\1/g;
0
 
_D_Author Commented:
thanks, just what I was looking for
0
All Courses

From novice to tech pro — start learning today.