Skip to content

Instantly share code, notes, and snippets.

@gotofritz
Created April 27, 2012 09:03
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 gotofritz/2507631 to your computer and use it in GitHub Desktop.
Save gotofritz/2507631 to your computer and use it in GitHub Desktop.
To have a $ in your replace strings in Javascript regular expressions, it needs to be escaped with another $ ($$) not a slash (\$)
"I <feeling> that".replace( /<(.+?)>/g, "\$$1" );
//won't work - will produce ""I $1 that""
"I <feeling> that".replace( /<(.+?)>/g, "$$$1" );
//works - "I $feeling that"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment