Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created January 12, 2014 04:42
Show Gist options
  • Save myndzi/8381049 to your computer and use it in GitHub Desktop.
Save myndzi/8381049 to your computer and use it in GitHub Desktop.
'use strict';
var assert = require('assert');
var regex = /^(\/?(([^/*]+\/)*(\*\*(\/|$))?)?)?([^/*]*(\*([^*/]*))?)$/;
regex.verify = function () {
var success = [
'/foo/bar',
'/foo/bar/',
'/foo/bar/baz.js',
'/foo/bar/*',
'/foo/bar/*.baz.js',
'/foo/bar/baz.*.js',
'/foo/bar/baz.js.*',
'/foo.js',
'**/foo',
'/**/foo',
'foo/**',
'foo/**/bar',
'**/*',
'/foo/**'
];
var failure = [
'bar.*.*js',
'foo/bar**/',
'foo/**/**/bar',
'*/**',
'*/foo',
'/*/foo',
'/foo/**.js'
];
success.forEach(function (str) { assert.equal(regex.test(str), true, str); });
failure.forEach(function (str) { assert.equal(regex.test(str), false, str); });
};
regex.verify();
module.exports = regex;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment