Regexes like that are a bit of a write-only language, but I think the (\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])?
in the middle catches the array indexes. It also doesn't recognize [*]
as an index.
It's hard to fix that properly, as array indexes can be almost arbitrary shell "expressions". In an integer-indexed array, the index is taken as an arithmetic expansion, and something like [i+j]
works to use the sum of i
and j
. In an associative array, it could be e.g. [$x$y]
for concatenation. It could also be [i+a[j]]
if one were to be doing something excessively complex in the shell. Parsing that for syntax highlighting would pretty much require a full parser, not a simple regex. (And then there's command substitutions, but let's not go there...)
Anyway, it's easy to make it accept the [*]
and one $
in front of the variable name, here's the changed part:
... (\[([[:space:]]*\$?[[:alnum:]_]+[[:space:]]*|[@*])\])? ...
^^^ ^^^^
And the resulting full line:
color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:space:]]*\$?[[:alnum:]_]+[[:space:]]*|[@*])\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"
As far as I can see, ${arr[]}
is an error, so I'm not sure if it should be highlighted in full or not.
If that's the regex from the latest version, you might want to consider also posting a bug report.