Reputation: 679
Hi I have a html snippet that looks like *hi<br>*hello<br/>*test<br />
I want this to be preformatted using javascript as
*hi<br>
*hello<br/>
*test<br />
Is there a regular expression and javascript to do this.
Upvotes: 0
Views: 999
Reputation: 36476
str = str.replace(/<br>/g,"<br />\n");
This means replace all new lines \n
with a <br />
Upvotes: 1
Reputation: 506
I believe this will help:
var str = '*hi<br>*hello<br/>*test<br />';
str.replace(new RegExp('<br\s*\\?>', 'i'), "$0\n");
That way you will keep diffrence between
,
and
.
Upvotes: 1
Reputation: 51
Could you use replace() to replace * with *\n? You'd end up with an extra \n at the start but saves using regex.
Upvotes: 0