m1759
m1759

Reputation: 35

How to check if string contains a certain word haskell

Suppose I have the following String: "Do you like cats AND dogs" I want to search the String for the word "AND" and replace it with "OR"

What I want to ask is if there is a function that can allow me to search and replace. I thought of using elem but I think it only works with Lists

Upvotes: 1

Views: 265

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 153102

Using the regex-applicative package:

Text.Regex.Applicative> replace ("OR" <$ string "AND") "cats AND dogs AND lizards"
"cats OR dogs OR lizards"

Upvotes: 2

Related Questions