1

I was asking myself if it possible to replace all the Environment.NewLine in a specific div with Regex? I tried some regex by myself but I didn't succeed in it. By the way, I know it's not the right way to parse HTML with Regex.

This is what I had so far:

Regex.Replace(text, @"(?<=<div class=""text"">.*?)" + Environment.NewLine + "(?=.*?</div>)", "<br/>");

Thanks!

tereško
  • 57,247
  • 24
  • 95
  • 149
vblinden
  • 370
  • 3
  • 16

2 Answers2

2
... + Regex.Escape(Environment.NewLine) + ...
leppie
  • 112,162
  • 17
  • 191
  • 293
1
Regex.Replace(text, 
  @"(?<=<div class=""text"">.*?)((?<!\n)\r\n|\n\r|\r|\n)(?=.*?</div>)", 
  "<br>");
Ωmega
  • 40,237
  • 31
  • 123
  • 190