?: is used when you want to group an expression, but you do not want to save it as a matched/captured portion of the string.
An example would be something to match an IP address:
Note that I don't care about saving the first 3 octets, but the (?:...) grouping allows me to shorten the regex without incurring the overhead of capturing and storing a match. Type: match, Date: 7/12/2015 3:29:13 PMAuthor: stackoverflow
If I apply the regex below over it:
I would get the following result:
Group 1: "http"
Group 2: "stackoverflow.com"
Group 3: "/"
But I don't care about the protocol - I just want the host and path of the URL. So, I change the regex to include the non-capturing group (?:):
Now, my result looks like this:
Group 1: "stackoverflow.com"
Group 2: "/"Type: match, Date: 7/12/2015 3:23:20 PMAuthor: stackoverflow