Others have suggested using libraries such as HTMLAgilityPack. The former is indeed a nice tool, but if you don't need HTML parsing functionality beyond what you have requested, a simple parser should suffice:
string ReplaceNewLinesWithBrIfNotInsideDiv(string input) {
int divNestingLevel = 0;
StringBuilder output = new StringBuilder();
StringComparison comp = StringComparison.InvariantCultureIgnoreCase;
for (int i = 0; i < input.Length; i++) {
if (input[i] == '<') {
if (i < (input.Length - 3) && input.Substring(i, 4).Equals("<div", comp)){
divNestingLevel++;
} else if (divNestingLevel != 0 && i < (input.Length - 5) && input.Substring(i, 6).Equals("</div>", comp)) {
divNestingLevel--;
}
}
if (input[i] == '\n' && divNestingLevel == 0) {
output.Append("<br/>");
} else {
output.Append(input[i]);
}
}
return output.ToString();
}
This should handle nested divs as well.