This was long time a limitation in Java. There was no API for getting the list of named capture groups.
See this question.
When working with Java versions that do not support this feature, all you can do is using external libraries.
If you don't need a map, you can use the solution that is described in the
Clojure Documentation. In your case the solution can be similar to this:
(let [matcher (re-matcher #"-(?<foo>\d+)-(?<bar>\d+)-(?<toto>\d+)-\w{1,4}$"
"http://www.bar.com/f-a-c-a-a3-spok-ser-2-phse-2-1-6-ti-105-cv-9-31289-824-gu")]
(re-find matcher)
(re-groups matcher)
(.group matcher "foo"))
Although this solution is not perfect (The matcher is a mutable Java object), it works.
As written in the other answer, that I linked, since Java 20, which was released on 21st of March 2023, there is a
solution.
(let [matcher (re-matcher #"-(?<foo>\d+)-(?<bar>\d+)-(?<toto>\d+)-\w{1,4}$"
"http://www.bar.com/f-a-c-a-a3-spok-ser-2-phse-2-1-6-ti-105-cv-9-31289-824-gu")]
(re-find matcher)
(re-groups matcher)
(.namedGroups matcher))
This gives you what you want.
I had to manually install the JDK 20. The JRE did not work for me. But after installing the JDK 20 Clojure takes it and it works for me. There was no configuration needed.
With ClojureScript obviously this does not work, at all.
java.util.regex.Pattern
object. – Rochellrochella