Regular expression not working Maven fileset

瘦欲@ 提交于 2020-01-03 16:50:10

问题


I am trying use regular expression in maven-assembly-plugin which is shown below. There are files with the names starts with ABC502. I am trying to copy only the rpms with the 3 or 4 in suffix. Below one is not working. rpm names are given below

ABC5023-buildnumber.rpm

ABC5024-buildnumber.rpm

ABC5025-buildnumber.rpm

ABC5026-buildnumber.rpm

<fileSet>
    <directory>${project.build.directory}/tar_content/stackcontents/</directory>
    <outputDirectory>scripts/data/rpms/</outputDirectory>
    <includes>
        <include>%regex[ABC502(3|4)]-*.rpm</include>
    </includes>
    <fileMode>0755</fileMode>
    <directoryMode>0755</directoryMode>
</fileSet>

回答1:


When you use a regular expression to include or exclude files with the %regex[...] syntax, all of the expression should be composed of the regular expression. You cannot mix a regular expression part with a normal part when it is used to match files.

Therefore, you need to use

<fileSet>
    <directory>${project.build.directory}/tar_content/stackcontents/</directory>
    <outputDirectory>scripts/data/rpms/</outputDirectory>
    <includes>
        <include>%regex[ABC502(3|4)-.*?\.rpm]</include>
    </includes>
    <fileMode>0755</fileMode>
    <directoryMode>0755</directoryMode>
</fileSet>

This will include all RPM files starting by ABC5023 or ABC5024.



来源:https://stackoverflow.com/questions/37417337/regular-expression-not-working-maven-fileset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!