summaryrefslogtreecommitdiff
path: root/jstests/core/regex_util.js
blob: 7d87ac5f283a27d9aa2aa4307e28da7014a8503d (plain)
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
// Tests for RegExp.escape

(function() {
var TEST_STRINGS = [
    "[db]",
    "{ab}",
    "<c2>",
    "(abc)",
    "^first^",
    "&addr",
    "k@10gen.com",
    "#4",
    "!b",
    "<>3",
    "****word+",
    "\t| |\n\r",
    "Mongo-db",
    "[{(<>)}]!@#%^&*+\\"
];

TEST_STRINGS.forEach(function(str) {
    var escaped = RegExp.escape(str);
    var regex = new RegExp(escaped);
    assert(regex.test(str), "Wrong escape for " + str);
});
})();