using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?><a.*?>(.*?)</a>)\s*<ul";
string input = @"<ul>
<li>
<a href=""#o"">Первый</a>
</li>
<li>
<a href=""#v"">Второй</a>
</li>
<li>
<a href=""#t"">Третий</a>
</li>
<li>
<a href=""#ch"">Четвертый</a>
</li>
<li>
<a href=""#p"">ПÑтый</a>
</li>
<li>
<a href=""#test"">ШеÑтой</a>
<ul>
<li>
<a href=""#so"">ШеÑтьОдин</a>
</li>
<li>
<a href=""#sd"">ШеÑтьДва</a>
</li>
<li>
<a href=""#st"">ШеÑтьТри</a>
</li>
<li>
<a href=""#sc"">ШеÑтьЧетыре</a>
</li>
<li>
<a href=""#sp"">ШеÑтьПÑть</a>
</li>
<li>
<a href=""#ss"">ШеÑтьШеÑть</a>
</li>
<li>
<a href=""#sss"">ШеÑтьСемь</a>
</li>
<li>
<a href=""#sv"">ШеÑтьВоÑемь</a>
</li>
<li>
<a href=""#sd"">ШеÑтьДевÑть</a>
</li>
</ul>
</li>
</ul>";
Match m = Regex.Match(input, pattern);
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