Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

regex

ply

I'm working on a simple translator from SQL INSERT statements to a dataset XML file to be used with DbUnit.

My current definition looks like this:

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

Now, I want to support case insensitive commands of SQL, for example, accept all of INSERT INTO, Insert Into, insert into and iNsErT inTO as the same thing.

I wonder if there is a way to PLY use re.I so that it will ignore the case, or yet another alternative to write the rule that I'm not familiar with.

like image 656
Elias Dorneles Avatar asked May 10 '12 16:05

Elias Dorneles


1 Answers

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

like image 123
9000 Avatar answered Sep 20 '22 18:09

9000