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

Discussion in 'Javascript' started by Jake Barnes, Feb 19, 2006.

  1. Jake Barnes

    Jake Barnes Guest

    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);
    }
     
    Jake Barnes, Feb 19, 2006
    #1
    1. Advertisements

  2. Jake Barnes wrote:
    > 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
     
    Janwillem Borleffs, Feb 19, 2006
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alvin Bruney

    Threads.. Session var lost, App var ok

    Alvin Bruney, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    543
    rooster575
    Dec 2, 2003
  2. thomson
    Replies:
    10
    Views:
    2,794
    Eliyahu Goldin
    Jun 20, 2005
  3. thomson
    Replies:
    0
    Views:
    553
    thomson
    Jun 20, 2005
  4. Fred
    Replies:
    3
    Views:
    489
    Alf P. Steinbach
    Aug 10, 2003
  5. Alex Vinokur
    Replies:
    4
    Views:
    680
    Ron Natalie
    Sep 24, 2003
  6. Tor Erik Soenvisen
    Replies:
    14
    Views:
    821
    Tim Roberts
    Nov 23, 2006
  7. Replies:
    1
    Views:
    421
    skyofdreams
    Mar 30, 2007
  8. maestro

    while var, but var ==16 != true

    maestro, Jul 14, 2008, in forum: Python
    Replies:
    3
    Views:
    391
Loading...