Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove consecutive <br> from string using regex c#

Tags:

c#

regex

I have following string regex

"choose to still go on the trip. <br><br>\r\nNote that when booking"

After converting it with regex I need to replace <br> tags with only one <br> so string would be like this

"choose to still go on the trip. <br>Note that when booking"
like image 815
user2160425 Avatar asked Dec 04 '25 16:12

user2160425


1 Answers

This can be done in another (safer) way, using HTML Agility Pack (open source project http://html-agility-pack.net).

It takes into account the various notations <br>, <br/>, <br /> without you having to worry about it. This means you can focus on the actual task: replacing duplicates.

See Remove chain of duplicate elements with HTML Agility Pack, it explains an approach on how to replace duplicates.

like image 188
L-Four Avatar answered Dec 06 '25 05:12

L-Four