I would like a regex that includes all filenames with a certain ending ex. “.err” but not if this filename starts with e.g. “test”. In other words include “*.err”-files but not “test-whatever.err”-files.
I have found that
(?!test.*\.err$).*\.err
excludes the test*.err files and that
.*\.err
includes all the *.err files, but I need them both in the same expression.
Also the fact that the “.err” can be written as “.ERR” or “.Err” must be taken into concideration for this regex to work properly for me.
All thoughts and ideas are appreciated!
Regards
Rickard
Use this
See it here online on Regexr
The important parts, that are different to yours:
Use anchors.
^and$are anchoring your pattern to the start and to the end of the string(?i)makes it “ignorecase”, so thaterrwill also match “ERR” or “ErR” andtestwill also match “Test” and TEST …You didn’t gave the language, but this features should work with the most flavours.