仅用于2个字符的正则表达式大写



我已经得到了下面的Git推送规则,它在下面的例子中工作得很好:

^(fix|feature|wip|dev-task|release)/([a-zA-Z]+)-d+-(w+-*)*

feature/ab-1234-fix

如何强制大写字母只适用于AB?只能有2个字符。

feature/AB-1234-fix

使用

^(fix|feature|wip|dev-task|release)/(AB|a[^b]|[^a]b|[a-zA-Z]|[a-zA-Z]{3,})-d+-(w+-*)*

看到证据。

--------------------------------------------------------------------------------
^                        the beginning of the string
--------------------------------------------------------------------------------
(                        group and capture to 1:
--------------------------------------------------------------------------------
fix                      'fix'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
feature                  'feature'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
wip                      'wip'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
dev-task                 'dev-task'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
release                  'release'
--------------------------------------------------------------------------------
)                        end of 1
--------------------------------------------------------------------------------
/                       '/'
--------------------------------------------------------------------------------
(                        group and capture to 2:
--------------------------------------------------------------------------------
AB                       'AB'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
a                        'a'
--------------------------------------------------------------------------------
[^b]                     any character except: 'b'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
[^a]                     any character except: 'a'
--------------------------------------------------------------------------------
b                        'b'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
[a-zA-Z]                 any character of: 'a' to 'z', 'A' to 'Z'
--------------------------------------------------------------------------------
|                        OR
--------------------------------------------------------------------------------
[a-zA-Z]{3,}             any character of: 'a' to 'z', 'A' to 'Z'
(at least 3 times (matching the most
amount possible))
--------------------------------------------------------------------------------
)                        end of 2
--------------------------------------------------------------------------------
-                       '-'
--------------------------------------------------------------------------------
d+                      digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
-                       '-'
--------------------------------------------------------------------------------
(                        group and capture to 3 (0 or more times
(matching the most amount possible)):
--------------------------------------------------------------------------------
w+                      word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
-*                      '-' (0 or more times (matching the most
amount possible))
--------------------------------------------------------------------------------
)*                       end of 3 (NOTE: because you are using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in 3)

最新更新