There is a text:

PROMPT SET VERIFY OFF SET FEEDBACK OFF SET LINESIZE 255 SET PAGESIZE 1000 PROMPT PROMPT Constraints Owned By Table PROMPT ========================== SELECT c.constraint_name "Constraint", Decode(c.constraint_type,'P','Primary Key', 'U','Unique Key', 'C','Check', 'R','Foreign Key', c.constraint_type) "Type", c.r_owner "Ref Table", c.r_constraint_name "Ref Constraint" FROM all_constraints c WHERE c.table_name = Upper('&&1') AND c.owner = Upper('&&2'); PROMPT PROMPT Constraints Referencing Table PROMPT ============================= SELECT c1.table_name "Table", c1.constraint_name "Foreign Key", c1.r_constraint_name "References" FROM all_constraints c1 WHERE c1.owner = Upper('&&2') AND c1.r_constraint_name IN (SELECT c2.constraint_name FROM all_constraints c2 WHERE c2.table_name = Upper('&&1') AND c2.owner = Upper('&&2') AND c2.constraint_type IN ('P','U')); SET VERIFY ON SET FEEDBACK ON SET PAGESIZE 1000 PROMPT 

I want to find all the expressions "SELECT ...;" using Python3 and re. * regular expressions.

The expression (SELECT. *;) Is too greedy and returns everything from the first "SELECT" to the last ";"

  • one
    To vskidku .*? less greedy and should help. - Mike
  • I'm afraid that the regulars are not solved. Perhaps split by ; will help you. - nick_n_a 2:26
  • The fact is that in string constants, in comments and in some other parts of the query, there may be ', in this case ' can be either an opening / closing, or a service apostrophe, or an independent apostrophe (comment). Distinguish ; is in a comment or string constant - I do not see the possibility. - nick_n_a
  • Thanks Mike, it works :) - srg

1 answer 1

.+? non-annoying version with ? earned:

 re.findall("(SELECT.+?);+", response.text, re.MULTILINE | re.DOTALL | re.IGNORECASE)