Match words that consist of specific characters, excluding between special brackets
There are essentially two problems with your pattern:
Never use
A-z
in a character class if you intend to match only letters (because it will match more than just letters1). Instead, usea-zA-Z
(orA-Za-z
).Using the
*
quantifier after the character class will allow empty matches. Use the+
quantifier instead.
So, the fixed pattern should be:
[A-Za-z'/\\%]+(?![^{]*})(?![^\[]*\])(?![^<]*>)
Demo.
1 The [A-z]
character class means "match any character with an ASCII code between 65 and 122". The problem with that is that codes between 91 and 95 are not letters (and that's why the original pattern matches characters like '[' and ']').