Skip to content

Instantly share code, notes, and snippets.

@92hackers
Created August 22, 2017 03:49
Show Gist options
  • Save 92hackers/bb777c40f81b80a026ed84077bd9da52 to your computer and use it in GitHub Desktop.
Save 92hackers/bb777c40f81b80a026ed84077bd9da52 to your computer and use it in GitHub Desktop.
javascript deals with back slach, useful when involved Windows OS
'C:\Users\Administrator/Desktop/7-42.pdf' is wrong.
should be 'C:\\Users\\Administrator/Desktop/7-42.pdf'
because \ is preserved to escape character.
const str = 'C:\\Users\\Administrator/Desktop/7-42.pdf'
str.replace(/\//g, '\\')
// => 'C:\\Users\\Administrator\\Desktop\\7-42.pdf'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment