开发者

Use RegEx to wrap lines of text with string

If I have:

bob\nwas\nhere

I would like RegEx to output:

*bob**was**here*

Where an asterisk was pl开发者_StackOverflowaced at the start and end of each line, and the new line character was removed.

I'm using JavaScript/jQuery.


var input = 'bob\nwas\nhere',
    re = /\n/g;

alert('*' + input.replace(re, '**') + '*');

Demo

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜