Match all * .js files except two (or more)

I'm looking for reg. expression to match all *. js in my / lib directory , excluding (for example) jquery.js and require.js .

^(\/lib/)([^\/]*)$

      

above only selects all .js files inside lib directory, but I'm not sure where to define the excluded part.

/lib/jquery.js
/lib/handlebars.sj
/librequire.js
/lib.test.js

      

+3


source to share


1 answer


Try this regex * (if I understood correctly):

\/lib\/(?!jquery|require).*\.js

      

It matches all files .js

within the directory /lib/

except jquery.js

and require.js

.



This is called negative lookahead and is used when you want to match something that is not followed by something else.

Please note that this regex does not match anything starting with jquery

or require

(after /lib/

), if you want it you can easily concatenate the words you want.

* I don't think regex is your best approach for this problem.

+7


source







All Articles