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
  • 58,060
  • 25
  • 98
  • 150
vblinden
  • 390
  • 3
  • 17

2 Answers2

2
... + Regex.Escape(Environment.NewLine) + ...
leppie
  • 115,091
  • 17
  • 196
  • 297
1
Regex.Replace(text, 
  @"(?<=<div class=""text"">.*?)((?<!\n)\r\n|\n\r|\r|\n)(?=.*?</div>)", 
  "<br>");
Ωmega
  • 42,614
  • 34
  • 134
  • 203