I want to match string like 12af-23f4-123d-
.
Although it is possible to use [0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-
Can I use nested format like [[0-9a-f]{4}\-]{3}
?
Asked
Active
Viewed 227 times
0

Wiktor Stribiżew
- 607,720
- 39
- 448
- 563

Shan
- 41
- 1
- 5
-
2`([0-9a-f]{4}\-){3}` so ? – splash58 Dec 26 '17 at 07:06
-
Straight brackets `[]` are a character class; parens `()` are used for grouping which gives you the ability to "nest" expressions. – Chris Martin Dec 26 '17 at 08:44
1 Answers
0
Your original regex:
[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-
can be simplified in
([0-9a-f]{4}\-){3}
or
(([0-9a-f]{4}\-){3})
depending on the fact that you want to use the whole match as a whole or not (e.g. backreference,...).
Tested on regex101:

Allan
- 12,117
- 3
- 27
- 51