Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive Regex in Python [duplicate]

I have following Python regex:

re =re.match(r'.*? from\s+(.*?)(\s.*|$)', q)

Here, q is a query like this:

Q1 = u"select * from dlpx_jobs where job_id=\\'531\\';"

Q2 = u"select * FROM dlpx_jobs where job_id=\\'531\\';"

Now, obviously, for Q1 the regex works because "from" is lowercase in the query but for Q2 regex doesn't work because in Q2 "from" is in Uppercase.

Is there any way through which the regex works for both the query irrespective of whether "from" is uppercase or lowercase?

like image 926
Vishal K Nair Avatar asked Dec 24 '22 10:12

Vishal K Nair


1 Answers

Try this:

expr = re.match(r'.? from\s+(.?)(\s.*|$)', q, re.IGNORECASE)
like image 121
Andrew Hare Avatar answered Dec 25 '22 23:12

Andrew Hare