Search code examples
regex-greedy

exclude an asset regex


I need to write a regex that will capture everything in a directory except one asset. Ex. I want to exclude /test1/test2/new.jpg and capture everything else in /test1/test2/

I tried the negative lookahead but doesn't seem to work.

/test1/test2/^(?!new.jpg).*


Solution

  • You don't need ^ in between:

    /test1/test2/(?!new.jpg).*
    

    See this: https://regex101.com/r/uHgBZc/1