yoleg
yoleg

Reputation: 381

Replacing New Line Character

I need a little help replacing a special character in a string using a regular expression that I just can't seem to figure out.

Here is the string that I have, and the special character is a "↵". Essentially I'd like to replace every "↵" with a comma.

var string = "http://espn.com↵http://yellowpages.com↵http://reddit.com↵http://usps.com http://uber.com↵http://cnn.com↵http://w3schools.com↵http://hitch.com↵http://sdsu.com↵http://sf.com↵http://kings.com"

A little background about what I'm doing, perhaps there is an easier way to do this. I'm getting the value of a textarea where each entry (url) is typed out on a new line and trying to format it into an array of urls.

The string above is what I'm getting after getting the value of the textarea.

Thanks for any help.

Upvotes: 1

Views: 397

Answers (1)

gurvinder372
gurvinder372

Reputation: 68373

If regex is not mandatory then try

string = string.split(/\n|\r|↵/).join( "," );

Upvotes: 2

Related Questions