Welcome! Please see the About page for a little more info on how this works.

+2 votes
in Regex by
closed by
(def matcher (doto (re-matcher #"(\d{2})\/(\d{2})\/(\d{4})" "12/02/1975 ")
(.groupCount matcher) ;; 3
(.group matcher 3) ;; "1975"
(nth matcher 3) ;; "1975"
(nth matcher 3 nil) ;; nil, but "1975" expected

seems like a bug in (nth <matcher-instance> <index> <not-found>) implementation for Matcher.

  • from the docs of .groupCount: "Group zero denotes the entire pattern by convention. It is not included in this count."
  • the check in RT.java in the nth implementation checks to make sure n < m.groupCount()
  • the check should be for n <= m.groupCount()
closed with the note: Fixed in 1.10.2-rc1

1 Answer

+2 votes
selected by
Best answer

Filed as https://clojure.atlassian.net/browse/CLJ-2585 and added a patch - nice catch!