-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathWildcard.js
37 lines (35 loc) · 982 Bytes
/
Wildcard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
API:
RegExp WildcardToRegExp(string wildcard);
*/
Packages.Define("IO.Wildcard", function (__injection__) {
eval(__injection__);
function WildcardToRegExp(wildcard) {
var regex = "";
for (var i = 0; i < wildcard.length; i++) {
var c = wildcard[i];
switch (c) {
case "*":
regex += ".*";
break;
case "?":
regex += ".";
break;
case "(": case ")":
case "[": case "]":
case "{": case "}":
case "*": case "+": case "?": case ".":
case "$": case "^":
case "\\": case "/":
regex += "\\" + c;
break;
default:
regex += c;
}
}
return new RegExp(regex);
}
return {
WildcardToRegExp: WildcardToRegExp,
}
})