in reply to Simple regex wordlist question
What you want is "The currect dict word contains the first letter, the currect dict word contains the second letter, ... and the currect dict word contains the last letter." Regexp are not good at doing "AND". It's usually better to do multiple matches, and AND the results of the matches.
Update: No, I suppose that's not quite right. You want "All letters of the currect dict word is in the specified word." A regexp character class can handle that quite well.
use strict; use warnings; my $input = <STDIN>; my ($re) = map qr/^[$_]*$/, join '', map quotemeta, $input =~ /(.)/g; my $dict = 'wordlist.txt'; open(my $dict_fh, '<', $dict) or die("Unable to open dictionary file: $!\n"); while (<$dict_fh>) { print if /$re/; }
Update: Note that the OP didn't mention each letter could only be used once, and he didn't mention that all the letters needed to be used, so I didn't add those restrictions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple regex wordlist question
by goibhniu (Hermit) on Sep 11, 2007 at 16:00 UTC | |
by goibhniu (Hermit) on Sep 11, 2007 at 21:00 UTC |