MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: help with DictionaryLookup[] and a type of regular expression

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109651] Re: help with DictionaryLookup[] and a type of regular expression
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Mon, 10 May 2010 06:38:45 -0400 (EDT)

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 at wolfram.com
User Interface Group
Wolfram Research, Inc.


  • Prev by Date: Re: How to write reports and books in Mathematica
  • Next by Date: Re: Number of ways of permutations to form a certain pattern of
  • Previous by thread: Re: help with DictionaryLookup[] and a type of regular expression
  • Next by thread: Re: help with DictionaryLookup[] and a type of regular expression