Add Vcs-Git and Vcs-Browser to debian/control
[greasemonkey-debian.git] / perl / convert2RegExp_1.js
blob3a1164ce9f50030a902c9d3f413b7be0ff8b5a02
2 // Converts a pattern in this programs simple notation to a regular expression.
3 // thanks AdBlock! http://www.mozdev.org/source/browse/adblock/adblock/
4 function convert2RegExp( pattern ) {
5 s = new String(pattern);
6 res = new String("^");
8 for (var i = 0 ; i < s.length ; i++) {
9 switch(s[i]) {
10 case '*' :
11 res += ".*";
12 break;
14 case '.' :
15 case '?' :
16 case '^' :
17 case '$' :
18 case '+' :
19 case '{' :
20 case '[' :
21 case '|' :
22 case '(' :
23 case ')' :
24 case ']' :
25 res += "\\" + s[i];
26 break;
28 case '\\' :
29 res += "\\\\";
30 break;
32 case ' ' :
33 // Remove spaces from URLs.
34 break;
36 default :
37 res += s[i];
38 break;
42 var tldRegExp = new RegExp("^(\\^(?:[^/]*)(?://)?(?:[^/]*))(\\\\\\.tld)((?:/.*)?)$")
43 var tldRes = res.match(tldRegExp);
44 if (tldRes) {
45 // build the mighty TLD RegExp
46 var tldStr =