develooper Front page | perl.beginners | Postings from May 2007

RegEx again

Thread Next
From:
yitzle
Date:
May 19, 2007 22:42
Subject:
RegEx again
Message ID:
ca5781c80705192242m303da806qcdf1f4a8534bc25c@mail.gmail.com
I got two arrays of strings.
I am trying to search to see if any of the strings of one array
matches a string of the other array.

Lists to search:
qw/big bad blue ball/, qw/box sand house/

Search list:
qw/brown black blue/

I should be able to get list #1 but not list #2 because the first list
has "blue" as does the search list.

# Look in
@list1 = qw/big bad blue ball/;
@list2 = qw/box sand house/;
@keywords = qw/brown black blue/;

# Add a ^ and $ so the strings match fully
push @search, qr/^$_$/ for ( @keywords );
$searchRegEx = join '|',@search;
print "1" if ( grep $searchRegEx, @list1 );
print "2" if (grep $searchRegEx, @list2);

Result: "12"

Um. Please help?
Thanks!

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About