0

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

Cyril I
  • 273
  • 3
  • 16
  • I think you can make the first parts optional `^([A-Z]([0-9][-_])?)?SPRINT[0-9]+` – The fourth bird Apr 11 '22 at 12:28
  • [rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "dev" || ($CI_COMMIT_BRANCH =~ "^([A-Z]([0-9][-_])?)?SPRINT[0-9]+") when: always - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH != "dev" || ($CI_COMMIT_BRANCH !~ "^([A-Z]([0-9][-_])?)?SPRINT[0-9]+") when: never ] -I'm using like this but the pipeline didn't triggers for [R1_sprint3] branch @Thefourthbird – Cyril I Apr 11 '22 at 12:46
  • The pattern matches for `R1_sprint3` but you have to make the pattern case insensitive. See https://regex101.com/r/3pIpC5/1 or use a character class A-Za-z and all variations for the word sprint like `^([A-Za-z]([0-9][-_])?)?[Ss][Pp][Rr][Ii][Nn][Tt][0-9]+` – The fourth bird Apr 11 '22 at 13:13
  • Now its working @Thefourthbird – Cyril I Apr 11 '22 at 13:20
  • Did you use `/i` or the longer pattern with all the variations? – The fourth bird Apr 11 '22 at 13:21
  • ($CI_COMMIT_BRANCH !~ (/^([A-Z]([0-9][-_])?)?SPRINT[0-9]+/i)) This is the command , I used – Cyril I Apr 11 '22 at 13:28

1 Answers1

0

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.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
  • fine thank you! can you explain "i" ? @The fourth bird – Cyril I Apr 11 '22 at 13:35
  • 1
    @CyrilI The `/i` flag makes the pattern case insensitive, so it will match `SPRINT` and `sprint` `SpriNt` etc.. – The fourth bird Apr 11 '22 at 13:39
  • https://stackoverflow.com/questions/72216766/how-do-i-use-docker-environment-variable-in-entrypoint-array-issue-facing-in-ku?noredirect=1#comment127596994_72216766 – Cyril I May 13 '22 at 07:35