开发者

Adding a new line using javascript

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.


str = str.replace(/<br>/g,"<br />\n");

This means replace all new lines \n with a <br />


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
.


Could you use replace() to replace * with *\n? You'd end up with an extra \n at the start but saves using regex.


If str is your HTML string

str = str.replace(/\n/g , "<br />");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜