The escape character in the Java language and the expression of the escape character in the regular syntax in the Java string.
There are 14 escape characters in ASCLL:
\o |
Null character (NULL) |
00h/0 |
\ n |
Line Break (LF) |
0ah/10 |
\ r |
Carriage return (CR) |
0dh/13 |
\ t |
Horizontal tab (HT) |
09h/9 |
\v |
Vertical tabulation (VT) |
0b/11 |
\a |
Bell (BEL) |
07/7 |
\b |
BACKSPACE (BS) |
08h/8 |
\f |
Page Break (FF) |
0ch/12 |
\’ |
Single quotation marks |
27h/39 |
\” |
Double quotes |
22h/34 |
\\ |
Back slash |
5ch/92 |
\? |
Question mark character |
3f/63 |
\ddd |
Any character |
Three-bit octal |
\xhh |
Any character |
Two-bit hexadecimal |
in a string or character, whenever a backslash appears, along with one or more of its characters being considered an escape character and attempting to parse it, it will be an error if it is not a valid escape character. This is true in most languages, but all escape characters may not be supported .
Language-to-escape character handling:
There are 11 supported in Java: \ r \ n \ \ \ \ \ \ \ \ \ \ \ \ \ddd \xhh , which is in Java with the backslash can only have these 11 cases, in addition to \b is considered to be wrong. such as "\c" or " \c " will be error, even if we do not intend to the former \c as an escape character but want to represent \ and C these two characters, However, because the language sees the slash will be the escape character to parse, so for the front and back of the person will be interpreted as an escape character and error. Therefore, if you want to express these two characters without error, you should deal with them so that the language does not treat them as escape character parsing by escaping the slash (let the language use the slash as a normal character rather than the beginning of the escaped character)-that is, "\\c" .
A string representation of a regular expression: (This is often the case when using strings to represent regular expressions in Java)
There is no special syntax in Java that directly represents a regular expression, it needs to be represented by a string (that is, each character in the regular expression is represented in a string), and JavaScript appears to be directly represented?
There are several metacharacters in the regular syntax ( ] has special meanings (such as * matches 0 or more in regular expressions), according to regular syntax to treat these characters as normal characters rather than as metacharacters, you need to use a slash escape (such as when we want to match the character itself, it should be escaped in the schema definition, i.e. \* ), it is obvious that the escape character of these metacharacters is represented by a string (such as ), which will be error-resolved by parsing the ASCLL escape characters as described above "\\*" . A more extreme example: In a string \ is a meta-character, in order to represent the of a regular expression in a string \ requires two slashes- \\ ; in regular expressions \ is also a meta-character, in order to match \ itself, according to the regular syntax to be escaped as \\ At this point, the string representation requires four slashes \\\\ .
There can be three escape characters in regular expressions: Some predefined regular expressions, such as \d that represent numbers, \w , and so on, regular syntax metacharacters when ordinary characters are treated with escape characters (special to normal), and escape characters in ASCLL (normal to special).
Summary (string form of regular expression): Defines a regular expression according to regular syntax, and then converts the expression to a string representation: a simple rule is any ' \ ' in a regular expression, which needs to be replaced with two ' \ ' in a string, (for ASCLL escape character backslash substitution).
The expression of the escape character of the language and the escape character of the regular expression