Is there a possibility to write a regex that matches for [a-zA-Z]{2,4} but not for the word test? Or do i need to filter this in several steps?
2 Answers
Sure, you can use a negative lookahead.
(?!test)[a-zA-Z]{2,4}
I don't know if you'll need it for what you're doing, but note that you may need to use start and end anchors (^ and $) if you're checking that an entire input matches that pattern. Otherwise, it could match something like ouaeghAEtest because it will still find four chars somewhere that aren't "test".
2 Comments
shrx
Also, for multiple word exclusions:
(?![test1,test2])[a-zA-Z]{2,4}Wiseguy
foobar.aaa.dsfbut there are strings likefoobar.test.dsfi dont want to match. so its not about replacing something or so.