Try these at the REPL:

(source re-find)
(source re-matches)

re-matches is closer to what you did in Java than re-find, which does something 
different (find the first match in the string, as opposed to determining 
whether the entire string matches the regex).

Andy

On Dec 18, 2012, at 1:32 AM, vernam wrote:

> 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?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to