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 63 times
0
Wiktor Stribiżew
- 561,645
- 34
- 376
- 476
Shan
- 11
- 1
- 4
-
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
- 11,650
- 3
- 27
- 49