Q:

C# Regular expressions negative lookahead exclude from match

somewhere in the text I have an a link with href 
  <a href="image-CoRRECTME.aspx?ALSO=ME&leaveme=<%= MyClass.Text %>">somelink</a>

I need to replace text in href attribue to lowercase except content of the <% %> brakets
should look like:
 <a href="image-correctme.aspx?also=me&leaveme=<%= MyClass.Text %>">somelink</a>

I was thinking something like this.. "href=\"([^\"]*[A-Z]+[^\"]*)(?:(?<!.*<%[^%]*%>.*)))\"" but its not working. 
Thanks! 

A:

Try this if you haven't figured it out already.
private void test()
{
    string t = @"<a href=""image-CoRRECTME.aspx?ALSO=ME&leaveme=<%= MyClass.Text %>&test2=<%= MyClass2.Text %>&last_test=nothing"">somelink</a>";
    string fixed_string = Regex.Replace(t, "(?<=href=\"|href=\"[^\"]*%>)([^\"]*?)(?=<%|\")", TestMatchEvaluator);
}

private string TestMatchEvaluator(Match m)
{
    return m.Value.ToLower();
}

