regex101.com (and probably others) can give an automated, technical breakdown of a regex:
Code:
/ ([^$&.]+)(?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)? /
1st Capturing Group ([^$&.]+)
Match a single character not present in the list below [^$&.]+
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
$&. matches a single character in the list $&. (case sensitive)
Non-capturing group (?:((?:\.\.\.)?(?:\$|&)[^\s]+)(?:(\s+)(.*))?)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group ((?:\.\.\.)?(?:\$|&)[^\s]+)
Non-capturing group (?:\.\.\.)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
\. matches the character . literally (case sensitive)
\. matches the character . literally (case sensitive)
\. matches the character . literally (case sensitive)
Non-capturing group (?:\$|&)
1st Alternative \$
\$ matches the character $ literally (case sensitive)
2nd Alternative &
& matches the character & literally (case sensitive)
Match a single character not present in the list below [^\s]+
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equal to [\r\n\t\f\v ])
Non-capturing group (?:(\s+)(.*))?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
3rd Capturing Group (\s+)
\s+ matches any whitespace character (equal to [\r\n\t\f\v ])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
4th Capturing Group (.*)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
The human explanation is that it matches:
a) Anything but $ & .
b) Anything but $ & . followed by three periods (optionally) then a $ or & and non-whitespace
c) Anything but $ & . followed by three periods (optionally) then a $ or & and non-whitespace, then whitespace and the rest of the string
I get the feeling that the regex won't quite work the way its author intended it to...