I understand the concept of writing regular expressions using capturing and non-capturing groups.
Ex:
a(b|c)
would match and capture ab and ac
a(?:b|c)
would match ab and ac but capture a
But how is it useful when I make a new custom grok pattern and what it means to use non-capturing groups.
Looking at a few existing grok patterns like the one below for HOUR:
HOUR (?:2[0123]|[01]?[0-9])
Here we can match the hour format using (2[0123]|[01]?[0-9])
as well.
What makes the grok pattern use the non-capturing expression here? Based on what parameters should I decide to use this (?:subex)
a(b|c)
usually capturesb
orc
(depending on whether the pattern matchedab
orac
), anda(?:b|c)
captures nothing at all. The difference is one of performance; why capture something when you don't need to do? – Six(2[0123]|[01]?[0-9])
as well", No surprise there; capturing doesn't change what a pattern matches. – Six