I've have some luck with the following command:
git diff --color-words='[^][<>()\{},.;:?/|\\=+*&^%$#@!~`"'\''[:space:]]+|[][<>(){},.;:?/|\\=+*&^%$#@!~`"'\'']'
but it doesn't seem to negate the square brackets properly in the first character class.
I've tried this:
git diff --color-words='[^\]\[<>()\{},.;:?/|\\=+*&^%#@!~`"'\''[:space:]]+|[\]\[<>(){},.;:?/|\\=+*&^%#@!~`"'\'']'
in order to make the square brackets literal, but it fails with the message fatal: Invalid regular expression
.
Edit:
The output I get is like so:
foobarfo]ob[ar
But what I'm after is:
fo]oob[ar