How to get PLY to ignore case of a regular expression?

You can inject flags into regexp using (?) syntax. Try '(?i)INSERT\s+INTO', it adds the flag to ignore case.


Internally, lex.py uses the re module to do its pattern matching.
If you need to supply optional flags to the re.compile() function, use the reflags option to lex. For example:

lex.lex(reflags=re.UNICODE)

This information is extracted from documentation sections 4.3 and 4.20
In your case, you can pass re.IGNORECASE to lexer:

import re
lex.lex(reflags=re.IGNORECASE) 

Your code is more readable if you pass flags this way.

Tags:

Python

Regex

Ply