Skip to content

Instantly share code, notes, and snippets.

@MystPi
Created July 24, 2021 13:07
Show Gist options
  • Save MystPi/62190417be0eea51a8a2ce03216a2c78 to your computer and use it in GitHub Desktop.
Save MystPi/62190417be0eea51a8a2ce03216a2c78 to your computer and use it in GitHub Desktop.
A regex to parse escaped strings.
import re
regex = re.compile(r'(["\']).*?(?<!\\)(\\\\)*?\1')
@gosoccerboy5
Copy link

gosoccerboy5 commented Jul 30, 2021

I made a slightly simpler regex:

/("|')[^\\\n]*?(\\\\)*\1/g

https://regex101.com/r/btR3uw/1

@MystPi
Copy link
Author

MystPi commented Jul 30, 2021

I made a slightly simpler regex:

/("|')[^\\\n]*?(\\\\)*\1/g

https://regex101.com/r/btR3uw/1

Oh, nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment