如何将这个Java正则表达式转换为Go的正则表达式语法?

huangapple go评论74阅读模式
英文:

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

问题

我正在尝试将这个Java正则表达式转换为Go的正则表达式语法:

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

这个正则表达式是用于匹配Clojure关键字的,取自JVM Clojure编译器。

英文:

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.

答案1

得分: 3

应该是这样的:

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

模式[\D&&[^/]]表示任何非数字但不是/,可以用扩展的否定字符类[^\d/]来表示。

英文:

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/].

huangapple
  • 本文由 发表于 2016年1月26日 02:12:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/34999380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定