On Sat, Aug 21, 2010 at 7:11 PM, CuppoJava <patrickli_2...@hotmail.com> wrote: > Hi Everyone, > > I'm extremely stuck on this simple regex question, which I'm sure > someone with a little more experience will be able to write in a > second. I would really appreciate the help. > > Given a string consisting of a's, b's, and spaces: "aaa bbb abb ab > bb" > > I want to tokenize this into string's of a's and b's. > eg. "aaa", "bbb", "a", "bb", "a", "b", "bb" > > AND also, I have to be able to tell which of the strings of b's was > preceded with an "a", and which was preceded by a space.
(->> "aaa bbb abb ab bb" (re-seq #"(?<=(.))?(\w)\2*") (map (fn [[s pre]] {:s s, :pre pre}))) returns a lazy seq: ({:s "aaa", :pre nil} {:s "bbb", :pre " "} {:s "a", :pre " "} {:s "bb", :pre "a"} {:s "a", :pre " "} {:s "b", :pre "a"} {:s "bb", :pre " "}) --Chouser http://joyofclojure.com/ -- 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