/
(?<!\\) # negative look-behind to make sure start is not escaped
(?: # start non-capture group for all possible match starts
# group 1, match dollar signs only
# single or double dollar sign enforced by look-arounds
((?<!\$)\${1,2}(?!\$))|
# group 2, match escaped parenthesis
(\\\()|
# group 3, match escaped bracket
(\\\[)|
# group