(defn re-quote [s]
  (let [special (set ".?*+^$[]\\(){}|")
        escfn #(if (special %) (str \\ %) %)]
    (apply str (map escfn s))))


(let [string "ab(c\\Sdef[A-Z]gh)i|kl^m"
      quoted (re-quote string)
      matches (re-matches (re-pattern quoted) string)]
  (println "string:" string)
  (println "quoted:" quoted)
  (println "mathes:" matches))