Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Created May 3, 2009 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duncanbeevers/106034 to your computer and use it in GitHub Desktop.
Save duncanbeevers/106034 to your computer and use it in GitHub Desktop.
(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