Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created July 1, 2019 04:58
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 isaacs/c2b12db30a49324325a3781302668408 to your computer and use it in GitHub Desktop.
Save isaacs/c2b12db30a49324325a3781302668408 to your computer and use it in GitHub Desktop.
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