Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created January 9, 2012 22:09
Show Gist options
  • Select an option

  • Save cowboy/1585239 to your computer and use it in GitHub Desktop.

Select an option

Save cowboy/1585239 to your computer and use it in GitHub Desktop.
pattern matching for tim
[
["/*", "/", "*"],
["/foo", "/", "foo"],
["/foo*", "/", "foo*"],
["/foo*.js", "/", "foo*.js"],
["/foo/*", "/foo/", "*"],
["/foo?", "/", "foo?"],
["/foo?.js", "/", "foo?.js"],
["/foo/?", "/foo/", "?"],
["/bar/foo", "/bar/", "foo"],
["/bar/foo*", "/bar/", "foo*"],
["/bar/foo*.js", "/bar/", "foo*.js"],
["/bar/foo/*", "/bar/foo/", "*"],
["/baz/bar/foo", "/baz/bar/", "foo"],
["/baz/bar/foo*", "/baz/bar/", "foo*"],
["/baz/bar/foo*.js", "/baz/bar/", "foo*.js"],
["/baz/bar/foo/*", "/baz/bar/foo/", "*"]
].map(function(arr) {
var fullpattern = arr[0], rootExpected = arr[1], patternExpected = arr[2];
var root = fullpattern.replace(/[*?].*$/, "").replace(/[^/]*$/, "");
var pattern = fullpattern.slice(root.length);
console.log(root, pattern);
return root === rootExpected && pattern === patternExpected;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment