<p dir="ltr">Build a grammar up from the clients, or not, but either way match each client to a named capture point rather than an array of anonymous matches.<br>
Then check on keys %+ for the client ids?</p>
<div class="gmail_quote">On 04/09/2014 6:32 pm, "Jacinta Richardson" <<a href="mailto:jarich@perltraining.com.au">jarich@perltraining.com.au</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
G'day folk,<br>
<br>
It's been a while, and I shall endeavour to arrange some kind of meeting before the year is out, I promise.<br>
<br>
Anyway, I've recently been thinking of a regular expression problem and wondered if anyone had any suggestions on how I should approach it.<br>
<br>
Consider this situation.  I have a number of clients and a page of text on which they might match.  I want to tell whether any of my clients match, but I also want to know which client matched.  I could solve this, this way.<br>

<br>
my %clients = (<br>
    031234 => "John Smith",<br>
     234345 => "Jane Brown",<br>
     345345 => "Jameel Bayan"<br>
);<br>
<br>
foreach my $client_id (keys %clients) {<br>
    my $client = $clients{$client_id};<br>
<br>
    my (first, $last) = split /\w+/, $client;<br>
    my $first_initial_only = substr($first, 0, 1);<br>
<br>
    my $match_first_initial_last = qr{$first_initial_only\s+$<u></u>last};<br>
    my $match_surname_first   = qr{$last\W+$first};<br>
<br>
    if(    $page =~ /$client/<br>
       ||  $page =~ $match_first_initial_last<br>
       || $page  =~ $match_surname_first<br>
     ) {<br>
            say "yay I matched $client_id";<br>
}<br>
<br>
Now there's an obvious improvement there, where I can make that all one regular expression against $page:<br>
<br>
      if(  $page =~ m{$client|$match_first_<u></u>initial_last|$match_surname_<u></u>first} ) {<br>
      }<br>
<br>
and that's great.  But what I really want to do is be able to build a regular expression to try to match all of my clients against the page, at once, and to still know who matched.  Mostly because the contortions I go to increase successful matches while limiting false positive matches are a little more complicated than the above.<br>

<br>
So ideally I'd like to do something like this:<br>
<br>
my ($match_full_name, $match_first_initial_last, $match_surname_first);<br>
<br>
foreach my $client_id (keys %clients) {<br>
    my $client = $clients{$client_id};<br>
<br>
    my (first, $last) = split /\w+/, $client;<br>
    my $first_initial_only = substr($first, 0, 1);<br>
<br>
    $match_full_name         .= qr{$client};<br>
    $match_first_initial_last .= qr{$first_initial_only\s+$<u></u>last};<br>
    $match_surname_first   .= qr{$last\W+$first};<br>
}<br>
<br>
if(    $page =~ $match_full_name<br>
       ||  $page =~ $match_first_initial_last<br>
       || $page  =~ $match_surname_first<br>
) {<br>
       # Which client_id did I match?<br>
}<br>
<br>
Does anyone have any suggestions for how that might be done?<br>
<br>
     J<br>
______________________________<u></u>_________________<br>
Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/melbourne-pm</a><br>
</blockquote></div>