The '( )' construct started life as a way of indicating a "capture group" which tells the regex engine to keep a copy of the (last) text that whatever is inside the parentheses matches. For example
will match 3 consecutive digits but capture the 2nd digit. Once the text is captured it can be referenced later in the pattern (often referred to as a back-reference) and/or in a replacement string and/or within the program that surrounds the matching operation.
This can be useful as in:
which will match 1 or more alphanumeric characters and save the value in match group #1. It will then scan forward looking for a second instance of the captured text. Given (say)
the cat sat on the mat
the first "the" text might be match in match group #1 and the '\1' will then match against the 2nd repetition of the characters. (By the way don't use this for real - there are MANY things that can go wrong with this example pattern and it is just to try to demonstrate back-references).
The parentheses can also be used to group portions of a pattern together. For example, if you want to find a repeated group of a digit followed by a space you could write
If you wrote
then the '+' quantifier would apply only to the '\s' but with the parentheses the quantifier will apply to whatever is between them. In effect it treats the inner sup-pattern as a single item and applies the quantifier to that.
As often happens during the evolution of regex pattern syntax, the parentheses have been pressed into service in many other ways. For example, if you combine the above to uses of parentheses, you soon realise that every time you use parentheses to group a set of regex operators, you also tell the regex engine to capture the matched text. However some regex engines only allow a limited number of captures (often 9 so that you can use '\1' to '\9' as back-references but will use '\11' as a way of expressing an octal literal character value etc - this just gets messy!) and so a "non-capturing" variant was introduced with the syntax '(?: )' - this works by letting you apply a quantifier to a sub-pattern without capturing the matched text.
There are many other variations of this but most start with '(? )' with some character(s) after the '?' that determines the operation within the parentheses.
I hope this explains what the '( )' is all about.