fork download
  1. import re
  2. p = '(?i)SELECT (?P<columns>.*) FROM (?P<source>.*?)(?: WHERE (?P<where_clause>.*))?;$'
  3. strs = ['select * from t1;', 'select * from t1 where c1 == 0;']
  4. for s in strs:
  5. m = re.match(p, s)
  6. if m:
  7. print(m.group("columns"))
  8. print(m.group("source"))
  9. print(m.group("where_clause"))
Success #stdin #stdout 0.02s 28384KB
stdin
Standard input is empty
stdout
*
t1
None
*
t1
c1 == 0