Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?!.*\-\-)((main|next|staging|dev(elop)?|test(ing)?)$|^((feat(ure)?|(bug|hot)?fix|docs|wip|test(ing)?)\/(?!\-)([a-z0-9\-]{1,50}(?<!-)\/(?!\-))?[a-z0-9\-]{1,100}(?<!-))$|^release\/v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$
/
gm

Description

A complete validation for GIT branch names. Includes typical branch names such as main and develop as well as feature, release branches and more.

Examples:

  • feat/add-i18n-module
  • release/v1.0.0
  • main
  • next/staging
  • docs/fix-typo
  • `bugfix/182/encode-slashes-in-url-query
Submitted by hexrw - 10 months ago