Difference between \r and \n

前端 未结 5 615
粉色の甜心
粉色の甜心 2020-12-02 23:09

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

Can someone explain it with an example?

5条回答
  •  悲&欢浪女
    2020-12-03 00:03

    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.

提交回复
热议问题