What is rn in javascript?

What is the difference between \r and \n in a regular expression?

Can someone explain it with an example?

What is rn in javascript?

asked Aug 10, 2010 at 16:23

\r is "Carriage Return" (CR, ASCII character 13), \n is "Line Feed" (LF, ASCII character 10). Back in the days, you had two ASCII characters at the end of each line to tell a printer what to do - CR would tell the printer to go back to the left edge of the paper, LF would advance to the next line.

Operating systems still have different conventions as to what the end of a line looks like -- some of them have \n\r, some have \n, some have \r\n.

In Javascript, you mostly deal with \n - this is how strings are typically switching to the next line. However, depending on what strings you are working with, you may be encountering \r as well.

answered Aug 10, 2010 at 16:27

EboMikeEboMike

75.7k14 gold badges158 silver badges166 bronze badges

5

Normally \r represents a carriage return character (ASCII 0x0d), and \n is a newline character (ASCII 0x0a). This page has a list of all the special characters, quoted here for completeness:

  • \f matches form-feed.
  • \r matches carriage return.
  • \n matches linefeed.
  • \t matches horizontal tab.
  • \v matches vertical tab.
  • \0 matches NUL character.
  • [\b] matches backspace.
  • \s matches whitespace (short for [\f\n\r\t\v\u00A0\u2028\u2029]).
  • \S matches anything but a whitespace (short for [^\f\n\r\t\v\u00A0\u2028\u2029]).
  • \w matches any alphanumerical character (word characters) including underscore (short for [a-zA-Z0-9_]).
  • \W matches any non-word characters (short for [^a-zA-Z0-9_]).
  • \d matches any digit (short for [0-9]).
  • \D matches any non-digit (short for [^0-9]).
  • \b matches a word boundary (the position between a word and a space).
  • \B matches a non-word boundary (short for [^\b]).
  • \cX matches a control character. E.g: \cm matches control-M.
  • \xhh matches the character with two characters of hexadecimal code hh.
  • \uhhhh matches the Unicode character with four characters of hexadecimal code hhhh.

answered Aug 10, 2010 at 16:25

Carl NorumCarl Norum

213k36 gold badges416 silver badges465 bronze badges

3

\n is linefeed

\r is carriage return

In windows, for example, line endings are \r\n. In the vast majority of other operating systems, they are \n.

What is rn in javascript?

HamZa

14.2k11 gold badges52 silver badges74 bronze badges

answered Aug 10, 2010 at 16:26

JhongJhong

2,65420 silver badges19 bronze badges

2

\r and \n are digital representations of the way you would advance to the next line on a typewriter. \r is a carriage return and \n is a newline (also known as a linefeed). On a typewriter, to go to the start of the new line, you would return the carriage to the leftmost position and then feed the paper up a line.

Unix uses \n to mean new line, Macs prior to OS9 used \r, and Windows uses \r\n.

answered Aug 10, 2010 at 16:28

\n --> For a new line

\r --> For carriage return

What is rn in javascript?

HamZa

14.2k11 gold badges52 silver badges74 bronze badges

answered Aug 10, 2010 at 17:45

SreejaSreeja

15111 bronze badges

What RN means?

2. RN is an abbreviation for registered nurse.

What does \r do in HTML?

“\r in html” Code Answer The \r metacharacter is used to find a carriage return character. \r returns the position where the carriage return character was found.

What is Slash r?

\r is a carriage return character; it tells your terminal emulator to move the cursor at the start of the line. The cursor is the position where the next characters will be rendered.

What is new line in JavaScript?

The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.