Search code examples
clojureclojurescript

Regex for replacing quotes in a string doesnot work in clojure


Am trying to replace the quotes in my string like so with an empty value:

(clojure.string/replace "Invalid password." #"\" " " ")

this, however, does not remove the quotes.

When I try:

(clojure.string/replace "Invalid password." #"\. " "testing")

this works

what could be the problem?


Solution

  • Not only, as in the comment mentioned, doesn't

    "Invalid password."
    

    contain a quote "\"". Furthermore, your regex has a space in it. But when you remove the space in the regex (#"\"" instead of #"\" "), and take "Invalid \"password\"." as argument, it works as you wanted:

    (clojure.string/replace "Invalid \"password\"." #"\"" " ")
    

    yields

    "Invalid  password ."