(?:)
creates a non-capturing group. It groups things together without creating a backreference.
A backreference is a part you can refer to in the expression or a possible replacement (by saying \1
or $1
etc – depending on flavor). You can also extract them from a match afterwards when using regex in a programming language. The main reason for using (?:)
is to avoid creating a new backreference, which avoids incrementing the group number which is especially important if you’re repeating a group and do not want to have unpredictable group numbers, and saves (a usually negligible amount of) memory