Tassilo Thank you for sharering your solution. I've just solved this problem in ClojureScript as follows. (defn foobar [acc s] (if-let [[_ pre m post] (re-find #"(.*?)(>>\d+)(.*)" s)] (recur (conj acc pre [m]) post) (conj acc s)))
(foobar [] "hello >>1 hello>>33") ;=> ["hello " [">>1"] " hello" [">>33"] ""] Thanks. 2012/2/13 Tassilo Horn <tass...@member.fsf.org>: > Takahiro Hozumi <fat...@googlemail.com> writes: > > Hi! > >> I want to make a sequence from string as follows. >> input: "hello >>1 world >>2" >> output: ("hello " [">>1"] " world " [">>2"]) >> >> What is efficient way to achieve this in ClojureScript? > > This is a JVM Clojure solution. I'm not sure if ClojureScript has > clojure.string, and probably the regex syntax differs a bit. But maybe > it gives you an idea. > > user> (defn foobar [s] > (map #(if (re-matches #"^>>\d+" %) [%] %) > (clojure.string/split s #"\p{Space}+"))) > #'user/foobar > user> (foobar "hello >>1 world >>2") > ("hello" [">>1"] "world" [">>2"]) > > Notice that `clojure.string/split' eats up the elements matching the > split regex (i.e., the spaces). Not sure if that's a problem for you. > > Bye, > Tassilo > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en