Strange behavior with brackets inside character class
I've encountered some unexpected behavior with brackets inside character classes in InDesign GREP and would like to get your expert opinions.
Test text: ab a[c] [d]
Test results:
- [a-z[] → matches: a, b, a, [, c, [, d (as expected)
- [a-z]] → matches: c], d] (two characters together)
- [a-z[]] → matches: c], d] (same as above)
- [a-z\[\]] → matches: a, b, a, [, c, ], [, d, ] (as expected)
Question: Why do [a-z]] and [a-z[]] produce the same result, matching c] and d] as two-character sequences rather than individual characters?
Logically, [a-z[]] should match "lowercase letters OR opening bracket OR closing bracket" individually, but it seems to behave differently.
Is this a bug, or am I missing something about how InDesign GREP handles nested brackets in character classes?
Workaround: Using [a-z\[\]] (escaping both brackets) works as expected.
Thanks for any insights!
