skip to Main Content

I want exclude paths which contains ‘locale’ and ‘test’ before extension. Paths can contain dots.

branch.name/packages/components/filename.js – true

branch.name/packages/components/filename.locale.js – fail

branch.name/packages/components/filename.test.js – fail

branch.name/packages/components/filename.utils.js – true

2

Answers


  1. You may call test() using the regex pattern:

    b(?:test|locale).w+$
    

    This matches test or locale followed by any extension at the end of the file.

    var files = ["branch.name/packages/components/filename.js",
                 "branch.name/packages/components/filename.locale.js",
                 "branch.name/packages/components/filename.test.js",
                 "branch.name/packages/components/filename.utils.js"];
    for (var i=0; i < files.length; ++i) {
        if (!/b(?:test|locale).w+$/.test(files[i])) {
            console.log("PASS => " + files[i]);
        }
        else {
            console.log("FAIL => " + files[i]);
        }
    }
    Login or Signup to reply.
  2. If you require at least one word character after a period to qualify as an extension, ^(?!.*(?:locale|test).w) will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search