Groups are a very useful feature of regular expressions, which are supported in all the flavors of regular expressions. Groups are used to combine multiple characters or multiple smaller components of regular expressions into a single unit. We create groups by placing a series of characters or subpatterns inside round brackets or parentheses, ( and ). For example, consider the following regex pattern:
(blue|red)
It means a capturing group that uses alternation. It either matches the letters b, l, u, and e or it matches the letters r, e, and d. In other words, it matches the strings blue or red, and more importantly, it creates a capturing group with either of the two matched strings. Each group becomes a single unit that can be used to apply certain constructs to the entire group. For example, anchors, boundary assertion, quantifiers, or alternation can...