In a string, I would like to replace any occurrences of:
<br /><br /><br /> (or more)
with:
<br /><br />
This has worked for replacing 2 or more consecutive occurrences of the letter e with an asterisk:
Dim strInput As String = "Thee brown fox jumped over the lazy dog."
Label1.Text = Regex.Replace(strInput, "e{2,}", "*")
Giving:
Th* brown fox jumped over the lazy dog.
These regex haven't worked for replacing two or more consecutive occurrences of the HTML breaks with an asterisk:
Dim strInput As String = "Thee <br /><br /><br /> brown fox jumped over the lazy dog."
Label1.Text = Regex.Replace(strInput, "\b<br />{2,}\b", "*")
Label1.Text = Regex.Replace(strInput, "\b<br />\b{2,}", "*")
Label1.Text = Regex.Replace(strInput, "\b<br />\b {2,}", "*")
Can anyone please give a syntax that will work?
(I could temporarily swap out all occurrences of the HTML breaks in the string with say [HTML-Linebreak] before executing the code if that would be easier. Then I could replace them back after.)
Try it, it worked with me: Regex.Replace(strInput, "(<br\s*/?>\s*){3,}", "<br /><br />")
Dim strInput As String = "Thee <br /><br /><br /><br /><br /><br /> brown fox jumped over the lazy dog."
Console.WriteLine(Regex.Replace(strInput, "(<br\s*/?>\s*){3,}", "<br /><br />"))