Created
November 2, 2016 06:07
-
-
Save nobeans/dae3f063459845b4b29b446e12a4bf74 to your computer and use it in GitHub Desktop.
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
function test(pattern, text, expected) { | |
const regexp = new RegExp(pattern) | |
const matched = regexp.test(text); | |
console.log(pattern, text, matched, (matched === expected) ? "OK" : "NG"); | |
} | |
test("a", "aaa", true); | |
test(".a.", "aaa", true); | |
test("x", "aaa", false); | |
test("^/a/b/c", "/a/b/c/d/e", true); | |
test("^/a / b/c", "/a / b/c/d/e", true); | |
test("^/a$/b/c", "/a$/b/c/d/e", false); // $が正規表現パターンとして使われてしまう | |
test("^/a.x/b/c", "/a#x/b/c/d/e", true); // .が正規表現パターンとして使われてしまう | |
//=> | |
// a aaa true OK | |
// .a. aaa true OK | |
// x aaa false OK | |
// ^/a/b/c /a/b/c/d/e true OK | |
// ^/a / b/c /a / b/c/d/e true OK | |
// ^/a$/b/c /a$/b/c/d/e false OK | |
// ^/a.x/b/c /a#x/b/c/d/e true OK | |
// | |
// *** time: 0.197457 *** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment