Venantius Venantius - 4 months ago 10
Java Question

How can I convert this Java regular expression to Go's regular expression syntax?

I'm trying to convert this Java regular expression to Go's regular expression syntax:


[:]?([\D&&[^/]]./)?(/|[\D&&[^/]][^/])


This regular expression is the regex for matching Clojure keywords, taken from the JVM Clojure compiler.

Answer

It should be

var pattern = regexp.MustCompile(`:?([^/\d].*/)?(/|[^\d/][^/]*)`) 

The pattern [\D&&[^/]] means any non-digit but a /, and it can be expressed with an extended negated character class [^\d/].

Comments