title: Replace a function block in a file using python
body: <p>I have a Ruby function code block in multiple files that I need to change in each file.</p>
  <p>The function that I am trying to replace looks something like this:</p>
  <pre><code>    def func1 options
          ...
          some code here
          ...
          def inner_func1 inner_options
              ...
              some code here
              ...
          end
          ...
          some more code here
          ...
      end
  </code></pre>
  <p>Each file has other functions in it but with different names. In some files I may have multiple tabs or spaces before.</p>
  <p>I want to replace the <code>func1</code> in each file with contents reading from another file (which can be a variable passed in the parameter).</p>
  <p>So far I have written this following python function for one such file to change:</p>
  <pre><code>import re
  
  a = open('main.rb').read() # file where I have the func1
  b = open('modified.rb').read() # file where I have only the modified func1 
  
  c = re.sub('(^[ \t]*)def func1:$.?\1end$',b,a, flags=re.DOTALL)
  
  print(c)
  
  with open('main.rb', 'w') as filetowrite:
      filetowrite.write(c)
          
  
  </code></pre>
  <p>However my <code>c</code> string does not show there was a change to anything.</p>
  <p>I am not sure if there is anything wrong with my regex.</p>