I have come across a regular expression that I don\'t fully understand - can somebody help me in deciphering it:
^home(?:\\/|\\/index\\.asp)?(?:\\?.+)?$
<
(?:)
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 (usually by saying \1
or $1
etc - depending on flavor). You can also usually extract them from a match afterwards when using regex in a programming language. The only reason for using (?:)
is to avoid creating a new backreference, which avoids incrementing the group number, and saves (a usually negligible amount of) memory