Clojure では、このソリューションのようなものを使用できます:正規表現の一致と string 内の位置のためのコンパクトな Clojure コード、つまり、 a を作成し、re-matcher
そこから情報を抽出しますが、re-matcher は ClojureScript に実装されているようには見えません。ClojureScript で同じことを達成するにはどうすればよいでしょうか?
編集:
に吸収される正規表現の修飾子を保持するために、補足関数を作成することになりましたre-pos
。
(defn regex-modifiers
"Returns the modifiers of a regex, concatenated as a string."
[re]
(str (if (.-multiline re) "m")
(if (.-ignoreCase re) "i")))
(defn re-pos
"Returns a vector of vectors, each subvector containing in order:
the position of the match, the matched string, and any groups
extracted from the match."
[re s]
(let [re (js/RegExp. (.-source re) (str "g" (regex-modifiers re)))]
(loop [res []]
(if-let [m (.exec re s)]
(recur (conj res (vec (cons (.-index m) m))))
res))))