language: Clojure (clojure 1.5.0-RC2)
date: 307 days 11 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
(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))