in reply to Re^2: Regex help
in thread Regex help

abcdecgf
has 7 unique letters.

A single regexp would be too convoluted I guess (I say that only because such a regexp is beyond my skills :-) update: or laziness :-)

#!/usr/bin/perl -nl if (length == 8) { $c = substr ($_, 2, 1); if (substr ($_, 5, 1) eq $c) { my %h; @h{split//,$_} = (1) x 8; print if keys %h == 7; } } __END__ perl match.pl /usr/share/dict/words Abednego abscised Acadians Acadia's Acalia's acerbest Adaiha's Adalia's Adelbert ... whirling whisking Wieche's wielders Winton's worker's writhing Yahweh's Yeargain Ygerne's Yorker's Zarger's Ziegfeld

update: changed to -nl to apply on /usr/share/dict/words

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^4: Regex help
by Anonymous Monk on Jun 23, 2007 at 02:13 UTC
    Thanks again.

    I tried your code on a dict file of words with length 8. Here're some of the results:

    ... abetters (not ok, t is repeated too) abigails (not ok) abillity (not ok, l is repeated too) abscises (not ok, s repeated more than twice) abscisin (not ok, i is repeated too) abscisse (not ok) acaudate (not ok) ...
    The result list is about 3300 words. I scanned through about 200 and couldn't find one that fits the regex...Maybe the word doesn't exist in the list...
      Did you run exactly the code I posted? You must have some cut'n'paste error. My result list is 776 words and none of those you report are included.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        This is what I've:
        # I didn't have the length == 8 line because # I'm only reading one file containing 8-letter words while (<FH>) { $c = substr ($_, 2, 1); if (substr ($_, 5, 1) eq $c) { my %h; @h{split//,$_} = (1) x 8; print if keys %h == 7; } }