title: Changing string in an m3u file with regex
body: <p>I am trying to make a change in an m3u file. The only thing I want to achieve is to replace what is in "tvg-name=" with "tvg-id="</p>
  
  <p>Here is the sample of m3u:</p>
  
  <pre><code>#EXTINF:0 user-agent="Firefox/100.0" tvg-id="" tvg-name="TR I beIN MOVIES PREMIER HD 1080P (beIN)" tvg-logo="" group-title="--SINEMA KANALLARI--",TR I beIN MOVIES PREMIER HD 1080P (beIN)
  http://xxxxxxx
  #EXTINF:0 user-agent="Firefox/100.0" tvg-id="" tvg-name="TR I beIN MOVIES PREMIER 2 1080P (beIN)" tvg-logo="" group-title="--SINEMA KANALLARI--",TR I beIN MOVIES PREMIER 2 1080P (beIN)
  http://xxxxxxx
  #EXTINF:0 user-agent="Firefox/100.0" tvg-id="" tvg-name="TR I beIN MOVIES ACTION 1080P (beIN)" tvg-logo="" group-title="--SINEMA KANALLARI--",TR I beIN MOVIES ACTION 1080P (beIN)
  http://xxxxxxx
  </code></pre>
  
  <p>I am not good at regex (not in python either, yet) but my code is below:</p>
  
  <pre><code>import re
  
  line = open('z.m3u', "r", encoding='utf-8')
  read_lines=line.read()
  pattern=re.compile(r'tvg-id=(".*?").tvg-name=(".*?")')
  matches=pattern.finditer(read_lines)
  
  for match in matches:
      tvg_id=match.group(1)
      tvg_name=match.group(2)
  
      w=re.sub(tvg_id,tvg_name,read_lines)
      print(w)
      line.write(w)
  </code></pre>
  
  <p>However, I cannot get the file written with the changes. A help would be appreciated.</p>
  
  <p>Thanks</p>