title: Select a specific set of characters in a file using regex in python
body: <p>In my code I have views defined like below.</p>
  <pre><code>VIEW Company_Person_Sd IS
     Prompt = 'Company'
     Company.Prompt = 'Company ID'
  SELECT company_id                          company_id,
         emp_no                              emp_no,
         Get_Person(company_id, emp_no)      person_id,
         cp.rowid                            objid,
         to_char(cp.rowversion)              objversion,
         rowkey                              objkey
  FROM   companies cp;
  </code></pre>
  <p>There can be more than one view defined in a single file (usually there are 20 or more).</p>
  <p>I want to get the whole view using a regex in python.</p>
  <p>I did the same thing to a method like below, using the following regex.(and it worked fine)</p>
  <pre><code>methodRegex = r&quot;^\s*((FUNCTION|PROCEDURE)\s+(\w+))(.*?)BEGIN(.*?)^END\s*(\w+);&quot;
  
  methodMatches = re.finditer(methodRegex, fContent, re.DOTALL | re.MULTILINE | re.IGNORECASE | re.VERBOSE)
          
          for methodMatchNum, methodMatch in enumerate(methodMatches, start=1):
              methodContent=methodMatch.group()
              methodNameFull=methodMatch.group(1)
              methodType=methodMatch.group(2)
              methodName=methodMatch.group(3)
  </code></pre>
  <p>method example</p>
  <pre><code>PROCEDURE Prepare___ (
     attr_ IN OUT VARCHAR2 )
  IS
    ----
  BEGIN
     --
  END Prepare___;
  
  PROCEDURE Insert___ (
     attr_ IN OUT VARCHAR2 )
  IS
    ----
  BEGIN
     --
  END Insert___;
  </code></pre>
  <p>When I try to do the same for views, it gives the wrong output.
  Actually I couldn't find how to catch the end of the view. I tried with semicolon as well, which gave a wrong output.</p>
  <p>My regex for views</p>
  <pre><code> viewRegex = r&quot;^\s*(VIEW\s+(\w+))(.*?)SELECT(.*?)^FROM\s*(\w+);&quot;
  </code></pre>
  <p>Please help me find out where I'm doing it wrong. Thanks in advance.</p>