using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"<span.*?(?:itemprop\s*=\s*""\s*name\s*""\s*)?class\s*=\s*""\s*itemprop\s*""\s*(?:itemprop\s*=\s*""\s*name\s*""\s*)?>(.*?)<\/span>";
string input = @" <div class=""txt-block"" itemprop=""contractors"" itemscope
itemtype=""home"">
<h4 class=""inline"">Employs:</h4> <a href=""/.../"" itemprop='url'><span class=""itemprop""
itemprop=""name"">Carp 1</span></a>, <a href=""/.../""
itemprop='url'><span class=""itemprop"" itemprop=""name"">Carp
2</span></a>, <a href=""/.../"" itemprop='url'><span class=""itemprop""
itemprop=""name"">Carp 3</span></a> <span
class=""tots"">|</span>
<span class=""see-more inline""> <a href=""/.../"" itemprop='url'>See full options</a>
</span>
</div>";
RegexOptions options = RegexOptions.Singleline;
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