title: Regex Match Resolution with High Bandwidth from Master m3u8 file
body: <p>I'm having a little problem with matching the highest bandwidth from m3u8 master file</p>
  <p>Here's the content of master.m3u8</p>
  <pre><code>#EXTM3U
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=149000,RESOLUTION=320x180,CODECS=&quot;avc1.66.30, mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 1
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=300000,RESOLUTION=320x180,CODECS=&quot;avc1.66.30, mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 2
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=500000,RESOLUTION=640x360,CODECS=&quot;avc1.66.30, mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 3
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=800000,RESOLUTION=640x360,CODECS=&quot;avc1.66.30, mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 4
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1000000,RESOLUTION=1280x720,CODECS=&quot;avc1.77.30, mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 5
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1299000,RESOLUTION=1280x720,CODECS=&quot;avc1.77.30, mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 6
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1499000,RESOLUTION=1280x720,CODECS=&quot;avc1.77.30, mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 7
  #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=62000,CODECS=&quot;mp4a.40.2&quot;,CLOSED-CAPTIONS=NONE
  https://testurl 8
  </code></pre>
  <p>I'm able to get the url by resolution. But the problem is some of the master m3u8 has three url with the same resolution but different bandwidth.</p>
  <p>My goal is, if I choose 1280x720 and if there will be multiple result with the same resolution, I want to get only the url with the highest bandwidth like in the example content. the highest is 1499000</p>
  <p>Here's my current code.</p>
  <pre><code>private static void TEST()
  {
  var f = File.ReadAllText(@&quot;C:\Users\MARK\Desktop\TEST\master.m3u8&quot;);
      
  string result = string.Empty;
      
      result = ParseM3u8Master(f, &quot;1280x720&quot;, 2);
      if (result == &quot;&quot;) {
          result = ParseM3u8Master(f, &quot;640x360&quot;, 2);
      }else if (result == &quot;&quot;){
          result = ParseM3u8Master(f, &quot;320x180&quot;, 2);
      }
      Console.WriteLine(result);
  }
  
  private const RegexOptions ML = RegexOptions.IgnoreCase | RegexOptions.Multiline;
  public static string ParseM3u8Master(string m3u8Master, string resolution, int group)
  {
      string result = string.Empty;
      string pattern = $@&quot;(?:RESOLUTION=({resolution}).*?)\n(https.+|http[-a-zA-Z0-9()@:%_\+.~#?&amp;//=])&quot;;
      if (Regex.IsMatch(m3u8Master, pattern, ML))
      {
          result = Regex.Match(m3u8Master, pattern, ML).Groups[group].Value;
      }
      return result;
  }
   
  </code></pre>