2012-01-07 18 views

risposta

7
(def my-re (java.util.regex.Pattern/compile "/")) ; to turn a string into a regex 
;; or just 
(def my-re #"/") ; if the regex can be a literal 

(clojure.string/split "foo/bar" my-re) 
+0

Wow, che era veloce! Molte grazie! –

+17

(re-pattern "/") farà altrettanto, leggermente più conciso di (java.util.regex.Pattern/compile "/") – NielsK

+0

Bello, grazie mille. –

11

È possibile utilizzare re-pattern:

(def var "/")    ; variable containing a string 
(def my-re (re-pattern var)) ; variable string to regex 

(clojure.string/split "foo/bar" my-re) 

Oppure, utilizzando una macro filo-ultima:

(->> "/" 
    (re-pattern) 
    (clojure.string/split "foo/bar")) 
Problemi correlati