Home > Back-end >  Specify repeated expression in gitlab regex
Specify repeated expression in gitlab regex

Time:05-11

How do you specify a repeated expression in a regular expression in gitlab? More generally, where is the gitlab regex syntax specified? All I could find was a few examples at https://gitlab.str.corp/help/user/packages/container_registry/index#regex-pattern-examples, which probably covers 95% of what users want, but not my case.

I am trying to write an image cleanup policy, where I need to specify a regex that matches image tags to delete. Our repo has two types of image tags:

  • version tags, which look like 1.2.3
  • commit tags, which look like abcdef1234567890abcdef123456789087654321 (a 40 digit id)

I want something that matches the commit tag. But depending on the regex version, that might be .{40} or .\{40\} or possibly one of those with a comma.

CodePudding user response:

GitLab uses re2 with Ruby's regexp to match the provided parameters. In the source code for GitLab, you can see the current regexp implementation here and its usage in registry cleanup.

Match tags in the 1.2.3 format:

\d \.\d \.\d 

Match tags with exactly 40 alphanumeric characters:

[A-z0-9]{40}
  • Related