Created
April 27, 2012 09:03
-
-
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 (\$)
This file contains 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
"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