using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?:<img|(?<!^)\G)\h*([-\w]+)=""([^""]+)""(?=.*?\/>)";
string input = @"<p>List of sample images.</p>
<img src=""https://placehold.it/250x100.jpg"" width=""250"" height=""100"" alt=""Dimensions Set"" />
<img src=""https://placehold.it/250x100/99cc00/000.jpg?text=JPG"" alt=""JPG"" /><br>
<img src=""https://placehold.it/250x100.gif?text=GIF"" alt=""GIF"" /><br>
<img src=""https://placehold.it/250x100/ff6600/000.png?text=PNG"" alt=""PNG"" /><br>
<img class=""no-ext"" src=""https://placehold.it/350x150?text=No Extension"" alt=""No Ext"" /><br>
<img src=""https://placehold.it/250x100.png"" custom-attr=""custom1"" another-attr=""custom2"" /><br>
<img class=""svg"" src=""https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg"" alt=""SVG"" /><br>
<img class=""webp"" src=""https://gstatic.com/webp/gallery/1.webp"" width=""100"" alt=""webP"" /><br>";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx