On Wed, Jul 29, 2009 at 9:49 AM, Rowdy Rednose 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;"
Look at clojure.contrib.str-utils2/replace. It accepts a function --
the fn will be called on each match, and its return value will be
inserted into the result string.
But that may not be quite what you want. If you want true string
generation, you'd need a template library.
-SS
On Jul 29, 9:
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"])
And reuse that pattern to generate a text that replaces