Of course, you can use negative viewing .
(?!test)[a-zA-Z]{2,4}
I don’t know if you need this for what you are doing, but note that you may need to use start and end bindings ( ^ and $ ) if you check that the entire input matches this pattern. Otherwise, it may correspond to something like ouaeghAEtest , because it will still find four characters that are not “tests”.
source share