code: def substitute_timestep(self, regex, timestep):
          
  
          # Make one change at a time, each change affects subsequent matches.
          timestep_changed = False
          while True:
              matches = re.finditer(regex, self.str, re.MULTILINE | re.DOTALL)
              none_updated = True
              for m in matches:
                  if m.group(1) == timestep:
                      continue
                  else:
                      self.str = (self.str[:m.start(1)] + timestep +
                                  self.str[m.end(1):])
                      none_updated = False
                      timestep_changed = True
                      break
  
              if none_updated:
                  break
  
          if not timestep_changed:
              sys.stderr.write('WARNING: no update with {0}.\n'.format(regex))
docs: Substitute a new timestep value using regex.