1

I would like to do something like that:

(def my_regex #"[1-9]")
(extract-string my-regex)
=> "[1-9]"

Is it possible in clojure?

1
  • 1
    why is this on hold? op posted expected results and most likely there are no attempted solutions, that's why he asked here in the first place. Do you want to say OP should have found the str solution 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 like extract-string should exist that returns the expected result. OP expects the desired result to be extractable from the regex object. What more do you want? Commented Dec 20, 2013 at 0:45

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.