I would like to do something like that:
(def my_regex #"[1-9]")
(extract-string my-regex)
=> "[1-9]"
Is it possible in clojure?
It's easy:
(.toString my_regex)
Actually, all Java (and Clojure) objects have .toString method returning its string representation.
There is also a str function in Clojure, which calls .toString on each of its arguments and concatenates results:
(str my_regex)
So, it's doing the same thing, but it's pure Clojure.
strsolution by intuition? Even Beschastny didn't know it and recommended use of .toString first. The Q clearly demonstrates an understanding of the problem being solved as OPs code clearly hints at the fact that a function likeextract-stringshould exist that returns the expected result. OP expects the desired result to be extractable from the regex object. What more do you want?