Search code examples
yaccflex-lexer

Flex/Yacc: What is the regex for SQL string literal?


I have the following rule:

string_literal \'(\\.|[^\\'])*\'

But this is assumes ' are escaped with a backslash but in SQL you can use '' to mean a single quote as well. What is the correct regex?


Solution

  • I adapted this solution:

    string_literal '([^\']|''|\')*'
    

    From this other post https://stackoverflow.com/a/6718928/1470961