Clojure regular expression extract text between two strings

Given a prefix and suffix string, how to extract all the text between them? In Clojure with the help of re-find, re-pattern and re-seq we can easily do that. The function should accept three arguments, the prefix, suffix and the string that contains patterns.

 
(defn make-literal [a]
  (.replace a "\"" "\\\"")
)
 
(defn extract-anything-between [prefix suffix from-string]
  (let [pattern (str (make-literal prefix) "([\\s\\S]*?)" (make-literal suffix))]
    (second (re-find (re-pattern pattern) from-string))
  )
)
 
 
(defn extract-anything-between-combine [prefix suffix from-string]
  (let [pattern (str (make-literal prefix) "([\\s\\S]*?)" (make-literal suffix))]
    (join "" (map #(second %) (re-seq (re-pattern pattern) from-string)) )
  )
)
 
 

Running examples

 
(def s "start-tag hello world end-tag")
(extract-anything-between "start-tag" "end-tag" s)
 

Output

 
" hello world "
 

This function only find the first match, to find all matches and combine them all together, use the second function

 
(def s "start-tag hello world end-tag hello world start-tag hello world 2 end-tag")
(extract-anything-between-combine "start-tag" "end-tag" s)
 
" hello world  hello world 2 "