[Haskell-cafe] Text search
GK at ninebynine.org
Mon May 16 05:57:36 EDT 2005
At 10:27 16/05/05 +0200, Gracjan Polak wrote:
>Simple question: I need a function that matches string in another string.
>find (isSuffixOf "needle") (inits "haystack")
>This one is beautiful, but not very practical. Could anybody point me to
>some haskell library that does some searching, using KMP for example?
foo = isPrefixOf (reverse "needle") (reverse "haystack with needle")
bar = isPrefixOf (reverse "needle") (reverse "haystack with pins")
Seems to work. And (by inspection) is linear in size of haystack.
More information about the Haskell-Cafe