regex - 使用 maven-replacer-plugin 选择性替换正则表达式

标签 regex maven maven-replacer-plugin

我想使用 maven-replacer-plugin 在我的 index.html 文件中重命名我的 javascript 导入语句。

但是,我只想在路径以 app 开头的地方执行此操作

index.html 片段

...
<!-- rename this one to app/something12345.js -->
<script src="app/something.js"></script>

<!-- leave this one as it is -->
<script src="vendor/angular.js"></script>
...

到目前为止,在我的 pom.xml 中,我对 maven-replacer-plugin 进行了此配置
 <plugin>
     <groupId>com.google.code.maven-replacer-plugin</groupId>
     <artifactId>replacer</artifactId>
     <version>1.5.2</version>
     <executions>
         <execution>
             <phase>prepare-package</phase>
             <goals>
                 <goal>replace</goal>
             </goals>
         </execution>
     </executions>
     <configuration>
         <file>target/${project.build.finalName}/index.html</file>
             <replacements>
                 <replacement>
                     <token>(\.js")</token>
                     <value>12345.js"</value>
                 </replacement>
             </replacements>
     </configuration>
 </plugin>

目前这显然将取代所有 .js火柴。

我可以在<token>中加入一些魔法咒语吗?节实现这一目标?

最佳答案

我设法使用以下方法做到了这一点

<replacement>
    <token>((app/)(.)*)(\.js")</token>
    <value>$112345.js</value>
</replacement>

虽然在我的实际应用中我替换了 12345${buildNumber}变量,所以语法是
<replacement>
    <token>((app/)(.)*)(\.js")</token>
    <value>$1${buildNumber}.js</value>
</replacement>

我希望这可能会使解决方案更容易理解

关于regex - 使用 maven-replacer-plugin 选择性替换正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25146073/

相关文章:

java - maven-replacer-plugin 和 windows 路径

具有多个文件的 maven-replacer-plugin

spring - 启动时Tomcat超时(spring maven hibernate)

maven - 什么时候可以安全删除本地Maven存储库?

java - 为具有不同模式的多个数据库生成 jOOQ 代码

javascript - 如何更改正则表达式以获得所需的正则表达式?

JavaScript 正则表达式获取引号字符串中的单词

regex - PostgreSQL 中的正则表达式排除

regex - 如何匹配与Perl中的特定模式不匹配的字符串?