Case insensitive Regex in Python
13,430
Try this:
expr = re.match(r'.? from\s+(.?)(\s.*|$)', q, re.IGNORECASE)
Related videos on Youtube
Author by
Vishal K Nair
Updated on June 04, 2022Comments
-
Vishal K Nair almost 2 years
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?
-
rock321987 over 6 yearsuse inline modifier
(?i)
-