sly icon indicating copy to clipboard operation
sly copied to clipboard

Parsing a string with escape characters

Open senyai opened this issue 4 years ago • 2 comments

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?

senyai avatar Nov 28 '21 20:11 senyai

Found it! r'"(\\.|[^\"])*"'. I think an example in the docs is needed.

senyai avatar Nov 29 '21 20:11 senyai

Let me try try

alingse avatar Apr 28 '22 12:04 alingse