Match Paths That Do Not Have __magic__ Folders

- 1 answer

I have a tree of components and inside of that tree are __magic_names__ folders (e. g. __tests__, __fixtures__, etc.). I want to filter out any files inside of these __magic_names__ folders. I'm using webpack and using require.context to slurp up my components - and I don't want my tests to ship with my production code.

I have the following regular expression, which is supposed to filter out every file path that contains a double-underscore. Unfortunately, it matches paths with __magic__ folders too:


Should work:


Should fail


Debuggex visualizes it this way:

Regular expression visualization

And here's a link to the Debuggex Demo for those who want to play around with it in more detail.

What am I doing wrong?



And it turns out that the issue was simply that I was using the wrong syntax for negative look-aheads. (?!=__) is wrong, (?!__) is right.

The corrected regular expression: