in reply to generate regular expression
idiom.(@array) = $string =~ /$pattern/g
Is that sort of what you were thinking of?my $base_data = 'ATCACTGGTTCCTGGACACTACCCTAAACCTTTGAGGA AATAACCGCTTTGTTGTTGCGATCGCCTAATAAATATC AGCGTCTTCGTATGATAAACCAATGCGGAAGTACAAAA TAAAGAGACTGTATTATGTTACT'; #the user submitted search pattern my $search_submitted = '2 CAC and 2 TTT'; #split it into chunks if applicable. my @search_chunks = split /and|or/, $search_submitted; #for each distinct pattern foreach my $chunk (@search_chunks){ #get the count we are looking for and the pattern we want to use my ($count, $search_string) = $chunk =~ /\s?(\d+)\s?([ATGCU\s\|]+) +/; #replace the |'s with character classes. $search_string =~ s/([ATGCU])\|([ATGCU])/[$1$2]/g; #replace all spaces $search_string =~ s/\s+//g; #run the match and see how many we get. my (@search_count) = $base_data =~ /$search_string/g; #check our results. if(scalar @search_count >= $count){ print "Found it!\n"; }else{ print "Nope...".scalar @search_count."\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: generate regular expression
by khoueiry (Initiate) on Apr 01, 2006 at 10:10 UTC |