yeah, that's it: ``` "escape this \! but keep this slash\\" .replace(/\\([^\\])/g, '$1') // => "escape this ! but keep this slash\" ```
-
-
Replying to @modernserf
I'm not familiar with the '$1' syntax, is it something else in JS?pic.twitter.com/SyJUzpNYK0
1 reply 0 retweets 0 likes -
Replying to @GalaxyKate
$1 is the value of the capture group, you need the parens in your regex
1 reply 0 retweets 0 likes -
Replying to @modernserf @GalaxyKate
oh nevermind, this doesn't work either
1 reply 0 retweets 0 likes -
Replying to @modernserf @GalaxyKate
aha, it works with the function version but not '$1'. (though it looks like someone found a different solution already) ``` " \\\\ escape this \! but keep this slash\\ " .replace(/\\([^\\])/g, (x) => x) // => " \\ escape this ! but keep this slash\ " ```
1 reply 0 retweets 0 likes -
Replying to @modernserf @GalaxyKate
oh i guess this one correctly unescapes `\\\\`
1 reply 0 retweets 0 likes -
Replying to @modernserf
The "correct" answer (so far) misses pairs of escaped slashes, so we're still looking for an answer: "escape this \! but keep this slash\\ and both of these \\\\"
1 reply 0 retweets 0 likes -
Replying to @GalaxyKate
like this? ``` "escape this \! but keep this slash\\ and both of these \\\\" .replace(/\\([^\\])/g, (x) => x) // => "escape this ! but keep this slash\ and both of these \\"
1 reply 0 retweets 0 likes -
Replying to @modernserf
Odd, I'm not getting *any* effect from that onepic.twitter.com/Zg8N5SYpTF
1 reply 0 retweets 0 likes -
Replying to @GalaxyKate
oh cool, i get different results in safari & chromepic.twitter.com/T5erFOhFKm
3 replies 1 retweet 3 likes
@kosamari Looks like there's a bug with the console formatter in one of those. You should be able to verify that JSON.stringify(result) is the exact same in both browsers. It works as expected in the JavaScript engine shells directly.
Please file a bug?pic.twitter.com/UIK8ignnBH
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.