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. Advertising

  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. Advertising

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. dongdong
    Replies:
    2
    Views:
    285
    Paul McGuire
    Mar 25, 2006
  2. werwer

    regx expression? (link included)

    werwer, Feb 2, 2008, in forum: Perl Misc
    Replies:
    2
    Views:
    99
    Brian McCauley
    Feb 2, 2008
  3. Duke of Hazard

    Regx to remove all characters after a match

    Duke of Hazard, Apr 18, 2008, in forum: Perl Misc
    Replies:
    3
    Views:
    176
    Gunnar Hjalmarsson
    Apr 18, 2008
  4. oldyork90

    regx, global efficiencies?

    oldyork90, Jun 9, 2008, in forum: Javascript
    Replies:
    4
    Views:
    91
    oldyork90
    Jun 10, 2008
  5. Cain
    Replies:
    3
    Views:
    97
Loading...

Share This Page