On Wed, Jul 29, 2009 at 9:49 AM, Rowdy Rednose<rowdy.redn...@gmx.net> wrote: > > Does anybody know an elegant way to have a regex pattern with > capturing groups like in this simple example: > > user=> (def pat #"^foo=([^;]*);bar=([^;]*);$") > #'user/pat > > user=> (re-seq pat "foo=F0o;bar=bAr;") > (["foo=F0o;bar=bAr;" "F0o" "bAr"])
user=> (re-seq #"(.*?)=(.*?);" "foo=F0o;bar=bAr;") (["foo=F0o;" "foo" "F0o"] ["bar=bAr;" "bar" "bAr"]) > And reuse that pattern to generate a text that replaces the groups > like this: > > user=> (re-gen pat "foo-gen" "bar-gen") > "foo=foo-gen;bar=bar-gen" (def my-keys (map second (re-seq #"(.*?)=(.*?);" "foo=F0o;bar=bAr;"))) user=> my-keys ("foo" "bar") user=> (apply str (mapcat #(vector %1 "=" %2 ";") my-keys ["foo-gen" "bar-gen"])) "foo=foo-gen;bar=bar-gen;" --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---