I am getting a HTML formatted string with tags. But there is an inconstancy with "<br>" tag. I am getting"<br>" tag in random formats which causes some extra space in text. So is there any solution to trim these multiple "<br>" tags with single one?
Example of text :-
"some text..... <br>"
"some text..... <br> <br>" // <-- this cause some extra space.
"some text..... <br>\n" // <-- this cause some extra space.
"some text..... <br>\n<br>" // <-- this cause some extra space.
"some text..... <br><br>\n <br>" // <-- this cause some extra space.
So in short, there can be multiple "<br>" tags with white spaces and \n character in it.
I need to replace that with single "<br>" tag. Can anyone help me with regex for the same?
Note:- I don't want to replace any other string in between two "<br>" tags except white space and "\n" .
Code written till now -
NSMutableString *temp = [[NSMutableString alloc] initWithString:html];
[temp replaceOccurrencesOfString:@"<br><br>" withString:@"<br>" options:0 range:NSMakeRange(0, [temp length])];
[temp replaceOccurrencesOfString:@"<br>\n<br>" withString:@"<br>" options:0 range:NSMakeRange(0, [temp length])];
[temp replaceOccurrencesOfString:@"<br>\n" withString:@"<br>" options:0 range:NSMakeRange(0, [temp length])];
It's a static string, needed regex for it.
<br>tags and trimming the string with\nandspace. If the trimmed string is empty you can replace it altogether.