sly
sly copied to clipboard
Parsing a string with escape characters
Hi!
I want to parse (lex) "He\"llo" "𝑤𝑜𝑟𝑙𝑑!" as two tokens He"llo and 𝑤𝑜𝑟𝑙𝑑!. I couldn't find anything that would work. I think #79 is a similar issue.
r'"(?:\\.|[^"\\])*"' idea from so didn't work as expected as it merged two strings.
@_(r'''("[^"\\]*(\\.[^"\\]*)*"|'[^'\\]*(\\.[^'\\]*)*')''') trick from medium.com didn't work.
All sly json parsers out there use r"\".*?\"" which is wrong.
Is it even possible?
Found it! r'"(\\.|[^\"])*"'. I think an example in the docs is needed.
Let me try try