Probably overkill on the capture groups.
The regex you use there contains a container capture group 4 that is quantified
like this ( ... ){3}
.
What that will do is overwrite the container capture buffer 3 times leaving
the last value captured within the capture group.
Moving on to the next level is a single inner group with which the outer group encapsulates, like this (( ... )){3}
so thats not needed, and you get the same affect of overwritting.
Moving even deeper, are three capture groups all separated by alternations.
They follow the same rules, each one will get overwritten if they can match
again during each successive 1..3 quantified passes.
Its only that one group match in the alternation cluster.
So, if you have identical adjacent data, it could be matched by the same
alternation cluster, leaving the other cluster groups empty.
So, this is not the approach if you want to match out-of-order parameters
in a string.
The way this is done is using lookahead assertions OR if you are using
an engine that can do conditionals.
The way to do it using conditionals is like this
(?:
.*?
(?:
( (?(1)(?!)) abc ) # (1)
| ( (?(2)(?!)) def ) # (2)
| ( (?(3)(?!)) ghi ) # (3)
)
){3}
It forces finding all of the capture group contents.
The way you are doing it is the same but without the conditionals,
and suffering the consequences as stated above.
Btw, Your regex above does not have any empty groups with that particular sample, But it has many problems.
lolspec:\/\/
( # (1 start)
spectator\.
( na | euw1 | eu | kr | oc1 | br | la1 | la2 | ru | tr | pbe1 ) # (2)
\.lol\.riotgames\.com:
( 80 | 8088 ) # (3)
( # (4 start)
( # (5 start)
( # (6 start)
[?&] region=
( NA1 | EUW1 | EUN1 | KR | OC1 | BR1 | LA1 | LA2 | RU | TR1 | PBE1 ) # (7)
) # (6 end)
| ( # (8 start)
[?&] gameID=
( [0-9]+ ) # (9)
) # (8 end)
| ( # (10 start)
[?&] encKey=
( .+ ) # (11)
) # (10 end)
) # (5 end)
){3} # (4 end)
) # (1 end)
Output
** Grp 0 - ( pos 0 , len 97 )
lolspec://spectator.euw1.lol.riotgames.com:80?region=NA1&gameID=44584&encKey=fghgdsv1134+ianfcuia
** Grp 1 - ( pos 10 , len 87 )
spectator.euw1.lol.riotgames.com:80?region=NA1&gameID=44584&encKey=fghgdsv1134+ianfcuia
** Grp 2 - ( pos 20 , len 4 )
euw1
** Grp 3 - ( pos 43 , len 2 )
80
** Grp 4 - ( pos 69 , len 28 )
&encKey=fghgdsv1134+ianfcuia
** Grp 5 - ( pos 69 , len 28 )
&encKey=fghgdsv1134+ianfcuia
** Grp 6 - ( pos 45 , len 11 )
?region=NA1
** Grp 7 - ( pos 53 , len 3 )
NA1
** Grp 8 - ( pos 56 , len 13 )
&gameID=44584
** Grp 9 - ( pos 64 , len 5 )
44584
** Grp 10 - ( pos 69 , len 28 )
&encKey=fghgdsv1134+ianfcuia
** Grp 11 - ( pos 77 , len 20 )
fghgdsv1134+ianfcuia