Created
July 1, 2019 04:58
-
-
Save isaacs/c2b12db30a49324325a3781302668408 to your computer and use it in GitHub Desktop.
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
var name = 'foo\\\\-bar' | |
var failbackExpr = /(\\*)-/g | |
var failbackMatch | |
var failback | |
while ((failbackMatch = failbackExpr.exec(name))) { | |
esc = failbackMatch[1] | |
esc = esc.length && esc.length % 2 | |
if (esc) continue | |
failback = name.slice(failbackMatch.index + 1) | |
name = name.slice(0, failbackMatch.index) | |
break | |
} | |
console.log({name, failback}) | |
// { name: 'foo', failback: '\\-bar' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment