Skip to content

Instantly share code, notes, and snippets.

@chemdemo
Created March 11, 2014 15:47
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 chemdemo/9488545 to your computer and use it in GitHub Desktop.
Save chemdemo/9488545 to your computer and use it in GitHub Desktop.
string replace
var s = '$0abc\\$1 $2 $3[$2]gr $4[x][1]'; // => $0, $2, $3[$2], $4[x][1]
s.replace(/((?!\\)\$\d+(\[[^\[\]]+\])*)/g, function(m, $1, $2, index) {
console.log(m, $1, $2, index);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment