To match [
, ]
literally, you should escape them. Otherwise it is used as metacharacter that represents a set of characters.
\[#[A-Fa-f0-9]{6}\]|\[[A-Fa-f0-9]{3}\]
In Java string litearls, \
should be escaped.
"\\[#[A-Fa-f0-9]{6}\\]|\\[[A-Fa-f0-9]{3}\\]"