2012-01-07 31 views

Respuesta

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, eso fue rápido! ¡Muchas gracias! –

+17

(re-patrón "/") también lo hará, un poco más conciso que (java.util.regex.Pattern/compile "/") – NielsK

+0

Bien, muchas gracias. –

11

Puede utilizar 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) 

O, utilizando una macro-hilo última:

(->> "/" 
    (re-pattern) 
    (clojure.string/split "foo/bar")) 
Cuestiones relacionadas