regx for newlines -- var regX = /\\n/g;

J

Jake Barnes

This was working for me, and now it isn't, and I can't remember what i
changed - the idea was to imitate the PHP command nl2br, which takes
newlines and turns them into newlines plus BR tags. Does anyone see
anything wrong with this?

function nl2br_js(myString){
var regX = /\\n/g;
var replaceString = '<br> \\n';
return myString.replace(regX, replaceString);
}
 
J

Janwillem Borleffs

Jake said:
This was working for me, and now it isn't, and I can't remember what i
changed - the idea was to imitate the PHP command nl2br, which takes
newlines and turns them into newlines plus BR tags. Does anyone see
anything wrong with this?

function nl2br_js(myString){
var regX = /\\n/g;
var replaceString = '<br> \\n';
return myString.replace(regX, replaceString);
}

function nl2br_js(myString){
var regX = /\n/g;
var replaceString = '<br>\n';
return myString.replace(regX, replaceString);
}


JW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top