Search code examples
regexelasticsearchnexussonatyperesource-cleanup

Can't negate nexus sonatype regex pattern


I am trying to create a Nexus clean up policy to prune all unused docker images in my repository except for my "flannel" docker image.

I have created ^((?!flannel).)*$ regex pattern for all strings excluding "flannel" and tested this pattern in regextester.com but unfortunately regex patterns are not working for me, eventhough it is stated here in the docs that Nexus Sonatype supports Reges Patterns.

I am using Nexus Sonatype OSS 3.21.1-01 version.


Solution

  • Sonatype documentation says that

    The expression engine uses an Elastic Search Regexp query syntax, from Apache Lucene.

    To match any string but the one containing flannel, you may use

    @&~(.*flannel.*)
    

    Details

    • @ - any string
    • & - intersection operator
    • ~(.*flannel.*) - any text but the one containing 0+ chars other than a newline, then flannel and then again any 0 or more chars other than a newline.