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

Reply via email to