Hi,
I've tinkered with clojures regexes and found a behavior I do not
understand.
(def regex "a(.*?)b(.*?)c(.*?)") ;; The RE string, a little
strange but valid
(def input "abbbcc") ;; The input, should match
completely
(import '[java.util.regex Pattern Matcher]) ;; Fst the direct java way
(def j-pattern (Pattern/compile regex))
(def j-matcher (.matcher j-pattern input))
(.matches j-matcher) ;; Ok
(def j-res ;; ["abbbcc" "" "bb" "c"]
(mapv (fn [g] (.group j-matcher g))
(range (inc (.groupCount j-matcher)))))
(def clj-pattern (re-pattern regex)) ;; Now clojure
(def clj-res (re-find clj-pattern input))
(= (.pattern clj-pattern) (.pattern j-pattern)) ;; Do we really use same
RE? (For me: yes)
(= clj-res j-res) ;; but the results differ:
;; clj-res ["abbbc" "" "bb"
""] is missing the last "c"
Could someone please explain what I'm missing?
Thanks
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en