A few notes about the pattern, some of which are already mentioned in the comment.
With the current variables, the pattern would be
([1])+.([db])+.([a-z])+.([a-z])+.
- Here, the
.
matches any character instead of a dot only.
- If you don't want to match 11, you should not use a quantifier for either the group or the character class
- Repeating the capture group
()+
would capture the value of the last iteration, you want the group value as a whole so you can repeat the character class instead
- As strings like
1
and db
are hardcoded, you don't really have to capture them
Taking that into account, you could use 2 capturing groups instead. As you are using re.match you can omit the anchor at the start and assert the end of the string using
1.db.([a-z]+)+.([a-z]+)
^ ^ ^
Dot group 1 group 2
Regex demo
q = re.compile(ID+r'.'+task+'.(['+environment+']+)+.(['+location+']+)', flags=re.I)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…