Created
May 3, 2009 15:55
-
-
Save duncanbeevers/106034 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() { | |
var s = "prefix arg1\narg2", | |
expected_capture = "arg1\narg2", | |
regexps = [ | |
/prefix\s+(.*)$/, // base | |
/prefix\s+(.*)$/m, /prefix\s+(.*)$/g, /prefix\s+(.*)$/mg, | |
/prefix\s([\s\S]*)$/, // base | |
/prefix\s([\s\S]*)$/m, /prefix\s([\s\S]*)$/g, /prefix\s([\s\S]*)$/mg | |
]; | |
for (var i = 0, len = regexps.length; i < len; i++) { | |
var regexp = regexps[i], | |
match = s.match(regexp); | |
if (!match) { | |
console.error('RegExp %o does not match %o', regexp, s); | |
continue; | |
} | |
var capture = match[1]; | |
if (expected_capture == capture) { | |
console.log('RegExp %o successfully captures %o from %o', regexp, match[1], s); | |
} else { | |
console.error('RegExp %o captures wrong args %o from %o', regexp, match[1], s); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment