How did we combine a sequence to commit branches in GitLab?

137 views Asked by At

I'm facing syntax issue

($CI_COMMIT_BRANCH =~ /^[A-Z][0-9][-_]SPRINT[0-9]+/i)
($CI_COMMIT_BRANCH =~ /^SPRINT[0-9]+/i)
($CI_COMMIT_BRANCH =~ /^[A-Z]SPRINT[0-9]+/i)]

(SPRINT-branch name) can you please help me to combine these split sequence into single command line

1

There are 1 answers

3
The fourth bird On BEST ANSWER

You can use:

^([A-Z]([0-9][-_])?)?SPRINT[0-9]+
  • ^ Start of string
  • ( Start a group
    • [A-Z] Match a single char A-Z
    • ([0-9][-_])? Optionally match a digit 0-9 and either - or _
  • )? Close the group and make it optional
  • SPRINT[0-9]+

The code can look like

($CI_COMMIT_BRANCH !~ (/^([A-Z]([0-9][-_])?)?SPRINT[0-9]+/i))

See the matches in this regex 101 demo.