How to write a regular expression to match a string literal where the escape is a doubling of the quote character?
fortran, ply, python, regex
Solution
A string literal is:
- An open single-quote, followed by:
- Any number of doubled-single-quotes and non-single-quotes, then
- A close single quote.
Thus, our regex is:
r"'(''|[^'])*'"
Problem
I am writing a parser using ply that needs to identify FORTRAN string literals. These are quoted with single quotes with the escape character being doubled single quotes. i.e. `'I don''t understand what you mean'` is a valid escaped FORTRAN string. Ply takes input in regular expression. My attempt so far does not work and I don't understand why. `t_STRING_LITERAL = r"'[^('')]*'"` Any ideas?