import re
p = '(?i)SELECT (?P<columns>.*) FROM (?P<source>.*?)(?: WHERE (?P<where_clause>.*))?;$'
strs = ['select * from t1;', 'select * from t1 where c1 == 0;']
for s in strs:
	m = re.match(p, s)
	if m:
		print(m.group("columns"))
		print(m.group("source"))
		print(m.group("where_clause"))