How to make PLY ignore the regex case?

I am working on a simple translator from SQL INSERT statements to an XML dataset file that will be used with DbUnit .

My current definition is as follows:

def t_INSERT(token):
    r'INSERT\s+INTO'
    return token

Now I want to support insensitive SQL command register, for example, take all INSERT INTO, INSERT INTO, INSERT INTOand INSERT INTOas one and the same.

I wonder if there is a PLY way to use re.Iit to ignore the case or another alternative to writing a rule that I am not familiar with.

+3
source share
2 answers

regexp (?). '(?i)INSERT\s+INTO', , .

+5

lex.py re .
re.compile(), reflags lex. :

lex.lex(reflags=re.UNICODE)

4.3 4.20
re.IGNORECASE lexer:

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

All Articles