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

6
  • I think you can make the first parts optional ^([A-Z]([0-9][-_])?)?SPRINT[0-9]+ Commented Apr 11, 2022 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 Commented Apr 11, 2022 at 12:46
  • The pattern matches for R1_sprint3 but you have to make the pattern case insensitive. See 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]+ Commented Apr 11, 2022 at 13:13
  • Now its working @Thefourthbird Commented Apr 11, 2022 at 13:20
  • Did you use /i or the longer pattern with all the variations? Commented Apr 11, 2022 at 13:21

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

fine thank you! can you explain "i" ? @The fourth bird
@CyrilI The /i flag makes the pattern case insensitive, so it will match SPRINT and sprint SpriNt etc..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.