a text matched by a part of a regular expression embraced with round
brackets will be saved into a special variable called "backreference".
It can be used in a later part of the same regular expression or
further in a scripting language. Ususally $1 corresponds to the first
par of round brackets, $2 corresponds to the second pair of round
brackets etc. and $0 corresponds to the whole regular expression.
On the opposite, if a (?: ) is used instead of ( ) , nothing will
be saved into a backreference.
Not saving unnecessary info frees memory and improves regex performance.
I did not go deep into your regex but i know that alternation
construct should be parsed from opening round bracket till closing
round bracket. So you should consider the whole
(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*) and not just \s*|\s*
(no matter that it contains nested alternation).