Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

the difference between \n and \r in javascript regex

Last post 08-05-2008, 5:48 PM by ddrudik. 1 replies.
Sort Posts: Previous Next
  •  08-05-2008, 6:33 AM 44950

    the difference between \n and \r in javascript regex

    hi

    I use regex in javascript to validate submitted form inputs.
    I know "\n" means "New line" and "\r" means "carriage return".
    but I can't seem to find the actual difference between them when I build my regular expression validation in javascript.
    looks like whenever an input of a form has a new line in it I can spot the new line by EITHER "\n" or "\r"

    can you provide some kind of example of a string that has "\n" in it and another that has "\r" in it so I can tell the difference ?

     

    thanks

     

  •  08-05-2008, 5:48 PM 44986 in reply to 44950

    Re: the difference between \n and \r in javascript regex

    \r = CR or carriage return

    \n = LF or line feed

    In Windows, when you create a new line by pressing the Enter key it issues a \r\n (CRLF) combination.  UNIX-formatted text files may more commonly have \n separating lines instead of \r\n as in Windows.


View as RSS news feed in XML