Skip to content

Instantly share code, notes, and snippets.

@yoko
Created February 20, 2009 09:15
Show Gist options
  • Save yoko/67389 to your computer and use it in GitHub Desktop.
Save yoko/67389 to your computer and use it in GitHub Desktop.
str = 'abcdefghijk';
re_1 = /.*(a).*/; // 1
re_2 = /.*(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k).*/; // 11
alert(str.replace(re_1, '$1111')); // $1 + "111"
alert(str.replace(re_2, '$1111')); // $11 + "11"
alert(str.replace(re_2, '$1'+'111')); // TRAP! $11 + "11"
alert(str.replace(re_2, function() {
return arguments[1]+'111'; // $1 + "111"
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment