I’m trying to run a Clojure regex on a Groovy source file to parse out the individual functions.
// gremlin.groovy
def warm_cache() {
for (vertex in g.getVertices()) {
vertex.getOutEdges()
}
}
def clear() {
g.clear()
}
This is the pattern I’m using in Clojure:
(def source (read-file "gremlin.groovy"))
(def pattern #"(?m)^def.*[^}]")
(re-seq pattern source)
However, it’s only grabbing the first line, not the multiline func.
It’s your regex, not Clojure. You request to match
def, then anything, then one char that is not equal to the closing brace. That char can be anywhere. What you want to achieve is this:(?sm)def.*?^}.