using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"<a\b[^>]*>(?!<\/a>)<a\b";
string input = @"<a href=""#1"">qwerty</a> - should not match
<a href=""#2"">qwe</a><a href=""#3"">rty</a> - should not match
<a href=""#4""><a href=""#5"">qwerty</a></a> - should match
<a href=""#6""><span><a href=""#7"">qwerty</a></span></a> - should match";
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