简体   繁体   English

Gitlab 提交匹配正则表达式

[英]Gitlab commits match regex

I am trying to add Commit Regex Rules in Gitlab .我正在尝试在 Gitlab 中添加提交正则表达式规则。 How do I implement below pattern :我如何实现以下模式:

Project-1 ,Project-2-1 , Project-3 are constant words and should always be in start of the commit message followed by a space , colon , space and a sentence at the end. Project-1 、Project-2-1 、 Project-3 是常量词,应始终位于提交消息的开头,后跟一个空格、冒号、空格和一个句子。

Project-1 : Changes done to fix the issue
Project-2-1 : Code changes
Project-3 : Bug squash
\b^(Project-1|Project-2-1|Project-3)\b : \w+

But the above regex is not matching a sentence at the end.但是上面的正则表达式最后没有匹配一个句子。

For the ranges of digits you might use a character class [1-3] or match 1+ digits using [0-9]+对于数字范围,您可以使用字符类[1-3]或使用[0-9]+匹配 1+ 个数字

If the digits after Project-digit can have an optional -digit part, you could make that optional using an optional non capturing group (?:-\\d)?如果 Project-digit 之后的数字可以有一个可选的 -digit 部分,您可以使用可选的非捕获组(?:-\\d)?使其成为可选的(?:-\\d)?

If there should be at least a non whitespace char \\S after the last space:如果最后一个空格后至少应该有一个非空白字符\\S

^Project-[1-3](?:-\d)? : \S.*

Regex demo正则表达式演示

For a broader match you could make use of a negated character class matching any char except a hypen at the beginning and match 1 or more digits:对于更广泛的匹配,您可以使用否定字符类匹配除开头的连字符之外的任何字符并匹配 1 个或多个数字:

^[^-]+-[0-9]+(?:-[0-9]+)? : \S.*

Regex demo正则表达式演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM