title: Regex to find all lines between start and end
body: <p>I am trying to get all lines between a line that matches a specific string until the occurrence of end line. The beginning pattern and end pattern could be in different places in the same file. My intention is to get the block of lines between the multiple occurrences. Basically, my file could like below</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER "ckjsdnvjn" (ID number, Type varchar2)
    BEFORE UPDATE OR INSERT ON TRIGGER_NAME
    FOR EACH ROW
    BEGIN
  IF INSERTING THEN
    :NEW.CREATED_D  := SYSTIMESTAMP;
  ELSE
    :NEW.CREATED_D  := :OLD.CREATED_D;
  END IF;
  :NEW.MODIFIED_D := SYSTIMESTAMP;
    END;
  /
  
  CREATE TABLE kjjknvfskjn 
  (
    ID NUMBER(19,0) NOT NULL,
    GRADE VARCHAR2( 4 ) NOT NULL,
    MODIFIED_D TIMESTAMP,
  
    CONSTRAINT jnflkvndflkn PRIMARY KEY( ID )
  );
  
  CREATE SEQUENCE kcnvlfnvlfnlk;
  
  CREATE OR REPLACE TRIGGER ME(ticket varchar2, note varchar2) AS
  BEGIN
    INSERT INTO jknsfjknv(
      cnkj,
      kknvlfn
    )
    VALUES (
      SYS_CONTEXT('lknvl','kvnldfkn'),
      '(kljkcsn: ' ||  lkdnv || ') ' || lknv
    );
  END ME;
  /
  </code></pre>
  
  <p>Expected Output:</p>
  
  <p>Match 1:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER "ckjsdnvjn" (ID number, Type varchar2)
    BEFORE UPDATE OR INSERT ON TRIGGER_NAME
    FOR EACH ROW
    BEGIN
  IF INSERTING THEN
    :NEW.CREATED_D  := SYSTIMESTAMP;
  ELSE
    :NEW.CREATED_D  := :OLD.CREATED_D;
  END IF;
  :NEW.MODIFIED_D := SYSTIMESTAMP;
    END;
  /
  </code></pre>
  
  <p>Match 2:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER ME(ticket varchar2, note varchar2) AS
  BEGIN
    INSERT INTO jknsfjknv(
      cnkj,
      kknvlfn
    )
    VALUES (
      SYS_CONTEXT('lknvl','kvnldfkn'),
      '(kljkcsn: ' ||  lkdnv || ') ' || lknv
    );
  END ME;
  /
  </code></pre>
  
  <p>My pseudo code is as follows, however I doesn't get the lines between the second matched line (CREATE OR REPLACE TRIGGER ME) since there is additional parenthesis. Is there any better way to get the desired output?</p>
  
  <pre><code>    with open(local_file, 'r') as f:
          textfile_temp = f.read()
          lines = textfile_temp.splitlines()
          STRING = 'CREATE OR REPLACE TRIGGER'
          SEARCH_END_STRING = 'end;'
          for line in lines:
              if re.search(STRING, line, re.IGNORECASE):
                  line = line.strip()
                  line = line.replace('(', '\(')
                  line = line.replace(')', '\)')
                  print line
                  SEARCH_PATTERN = r'(' + line + ')(.*?)(' + SEARCH_END_STRING + ')'
                  SEARCH_REGEX = re.compile(SEARCH_PATTERN, re.IGNORECASE|re.DOTALL|re.MULTILINE)
                  match = SEARCH_REGEX.search(textfile_temp)
                  print match.group()
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER ME\(ticket varchar2, note varchar2\) AS
  AttributeError: 'NoneType' object has no attribute 'group'
  </code></pre>