From: Michael Stern on
Is there an elegant way to do dictionary searches that match specified
kinds of character repetition? For example, to search for six letter
words that start with "d" and end with "k", where the third and fourth
letter are the same?

Finding six letter words that start with "d" and end with "k" is easy --

DictionaryLookup[{"English", RegularExpression["d....k"]}]

But how do we restrict the answer to words where the third and fourth
letters are the same?

Thanks,

Michael=

From: John Fultz on
On Sun, 9 May 2010 07:51:46 -0400 (EDT), Michael Stern wrote:
> Is there an elegant way to do dictionary searches that match specified
> kinds of character repetition? For example, to search for six letter
> words that start with "d" and end with "k", where the third and fourth
> letter are the same?
>
> Finding six letter words that start with "d" and end with "k" is easy --
>
> DictionaryLookup[{"English", RegularExpression["d....k"]}]
>
> But how do we restrict the answer to words where the third and fourth
> letters are the same?
>
> Thanks,
>
> Michael==

There's probably a way to do this using RegularExpression[], but I find it
easier (despite having thoroughly absorbed regular expressions in my Perl days)
to express these things using the more Mathematica-like StringExpressions. In
this case,

DictionaryLookup[{"English", "d" ~~ _ ~~ x_ ~~ x_ ~~ _ ~~ "k"}]

using the named pattern to denote a repeated character. It's more verbose, but
its meaning is dead obvious to anybody with even just a passing familiarity with
Mathematica's pattern matcher.

Sincerely,

John Fultz
jfultz(a)wolfram.com
User Interface Group
Wolfram Research, Inc.

From: Albert Retey on
Am 09.05.2010 13:51, schrieb Michael Stern:
> Is there an elegant way to do dictionary searches that match specified
> kinds of character repetition? For example, to search for six letter
> words that start with "d" and end with "k", where the third and fourth
> letter are the same?
>
> Finding six letter words that start with "d" and end with "k" is easy --
>
> DictionaryLookup[{"English", RegularExpression["d....k"]}]
>
> But how do we restrict the answer to words where the third and fourth
> letters are the same?

I guess you could do it with a regexp too, but in this case it was
easier for me to create a StringExpression:

DictionaryLookup[{"English", _ ~~ _ ~~ x_ ~~ x_ ~~ _ ~~ _}]

hth,

albert

From: Albert Retey on
Am 10.05.2010 12:39, schrieb Albert Retey:
> Am 09.05.2010 13:51, schrieb Michael Stern:
>> Is there an elegant way to do dictionary searches that match specified
>> kinds of character repetition? For example, to search for six letter
>> words that start with "d" and end with "k", where the third and fourth
>> letter are the same?
>>
>> Finding six letter words that start with "d" and end with "k" is easy --
>>
>> DictionaryLookup[{"English", RegularExpression["d....k"]}]
>>
>> But how do we restrict the answer to words where the third and fourth
>> letters are the same?
>
> I guess you could do it with a regexp too, but in this case it was
> easier for me to create a StringExpression:
>
> DictionaryLookup[{"English", _ ~~ _ ~~ x_ ~~ x_ ~~ _ ~~ _}]

I just realized that you wanted the above to be restricted, not an
entirely new lookup. This would do that (I think you did guess already...)

DictionaryLookup[{"English", "d" ~~ _ ~~ x_ ~~ x_ ~~ _ ~~ "k"}]

albert