Created
January 9, 2012 22:09
-
-
Save cowboy/1585239 to your computer and use it in GitHub Desktop.
pattern matching for tim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| ["/*", "/", "*"], | |
| ["/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