Python正则表达式来匹配和替换gradle依赖项outpu

2024-05-16 03:29:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我是正则表达式和Python的超级新手,但我想实现这一点。在

我有以下输入:

\--- org.projectlombok:lombok:1.+ -> 1.16.6

+--- org.springframework:spring-aspects: -> 4.1.7.RELEASE
|    \--- org.aspectj:aspectjweaver:1.8.6
+--- org.springframework.boot:spring-boot-starter-web: -> 1.2.6.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.2.6.RELEASE
|    |    +--- org.springframework.boot:spring-boot:1.2.6.RELEASE
|    |    |    +--- org.springframework:spring-core:4.1.7.RELEASE
|    |    |    \--- org.springframework:spring-context:4.1.7.RELEASE

需要获取一个Python脚本、正则表达式来删除行开头的“\”“-”“+”和空格,并将“->;”之前的单词或空格替换为“->;”之后的单词或空格

因此输出应为:

^{pr2}$

顺便说一下,这是项目的gradlew dependencis的输出。也许有办法从gradlew那里得到这个输出?在

好的,这段代码用Python实现:

^{3}$

输出:

org.projectlombok:lombok:1.16.6

org.springframework:springaspects:4.1.7.RELEASE
org.aspectj:aspectjweaver:1.8.6
org.springframework.boot:springbootstarterweb:1.2.6.RELEASE
org.springframework.boot:springbootstarter:1.2.6.RELEASE
org.springframework.boot:springboot:1.2.6.RELEASE
org.springframework:springcore:4.1.7.RELEASE
org.springframework:springcontext:4.1.7.RELEASE

Tags: orggtrelease单词boot空格starterspring
1条回答
网友
1楼 · 发布于 2024-05-16 03:29:59

gradle是内置依赖关系管理设计的,不知道为什么要使用python。一个简单的gradle任务可以为您编写文件。下面的操作将通过运行gradle writeDependencyFile来执行

task writeDependencyFile << {
    File output = new File("$project.rootDir.absolutePath/dependencies.txt")
    configurations.compile.each { File file ->
        output.append("${file.name.substring(0, file.name.lastIndexOf('.'))}\n")
    }
}

相关问题 更多 >