开发者

Use RegEx to wrap lines of text with string

开发者 https://www.devze.com 2023-02-14 12:05 出处:网络
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 remo

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

精彩评论

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