I have this
str = testString.replace(/<div style="(.*?)">(.*?)<\/div><div style="\1">/g, '<div style="$1">$2<br>');
It removes
<div style="text-align: right;">text1</div>
<div style="text-align: right;">text2</div>
into
<div style="text-align: right;">
text1<br>text2
</div>
Great!
What if i have multiple <div>‘s?
How can i make
<div style="text-align: right;">text1</div>
<div style="text-align: right;">text2</div>
<div style="text-align: right;">text3</div>
<div style="text-align: right;">text4</div>
into
<div style="text-align: right;">
text1<br>text2<br>text3<br>text4
</div>
?
Thou cannot use regex for complex HTML manipulations! Please see this question.
You could manipulate the DOM using jQuery to achieve the same result!
Please see this jsfiddle example for a possible alternative.
This is the jQuery code from the fiddle, assuming the requred divs are in a wrapping div with the id
toParse.