scader
scader

Reputation: 525

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 placed at the start and end of each line, and the new line character was removed.

I'm using JavaScript/jQuery.

Upvotes: 0

Views: 465

Answers (1)

Matt Ball
Matt Ball

Reputation: 359966

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

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

Demo

Upvotes: 3

Related Questions