使用正则表达式匹配器重写 sbt 工件以去除版本信息
RegEx 大师想要:我想在打包 sbt 项目时去掉库名称。也就是说,如果我的依赖项被调用,
val in = "scala-swing-2.9.0-1.jar"
我想将名称重写为
"scala-swing.jar"
E.g. 方法
def rewrite(p: util.matching.Regex, s: String) = s match {
case p(name) => name + ".jar"
case _ => s
}
给定我尝试过的
rewrite("""([^-_]*)[-_].*.jar""".r, in) // gives "scala.jar"
并且
rewrite("""(.*)[-_]\d.*.jar""".r, in) // gives "scala-swing-2.9.0.jar"
...
编辑:
奖金问题:
val in2 = "audiowidgets_2.9.0-1-0.10-SNAPSHOT.jar"
require(rewrite( ???, in2 ) == "audiowidgets.jar")
val in3 = "jsyntaxpane-0.9.5-b29.jar"
require(rewrite( ???, in3 ) == "jsyntaxpane.jar")
RegEx guru wanted: I want to strip library names in packaging an sbt project. Namely if my dependency is called
val in = "scala-swing-2.9.0-1.jar"
I want to re-write the name as
"scala-swing.jar"
E.g. given a method
def rewrite(p: util.matching.Regex, s: String) = s match {
case p(name) => name + ".jar"
case _ => s
}
I tried
rewrite("""([^-_]*)[-_].*.jar""".r, in) // gives "scala.jar"
and
rewrite("""(.*)[-_]\d.*.jar""".r, in) // gives "scala-swing-2.9.0.jar"
...
EDIT:
Bonus questions:
val in2 = "audiowidgets_2.9.0-1-0.10-SNAPSHOT.jar"
require(rewrite( ???, in2 ) == "audiowidgets.jar")
val in3 = "jsyntaxpane-0.9.5-b29.jar"
require(rewrite( ???, in3 ) == "jsyntaxpane.jar")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我终于知道他们在谈论“贪婪”和“不情愿”的属性了......
Finally I know what they are talking about with the 'greedy' and 'reluctant' attributions...
你或许也可以采用更简单的方法:
You could perhaps get away with something simpler too: