Start and end start symbols of a row: ^ end Symbol: $ for example, ^ cat should be interpreted as C as the first character of a line, followed by a, followed by T
Example: String STR = "catabdcatdetfcat"
^ Cat: Verify that the row starts with C followed by a and then t
Cat $: Verify that the row ends with T and the second to last character is a and the third to last character is C
^ Cat $: starts with C, then a-> T, and ends with a row: data rows with only three letters of cat
^ $: Ends immediately after the start: blank line, excluding any characters
^: The beginning of a row. It can match any row because each row has a beginning.
Bytes --------------------------------------------------------------------------------------------------------------
Character group: [] indicates: "or" For example: [ABC]: A, B, or C
Example: String STR = "My name is yangkai ";
A [Mn]: Find the words m or N after.
[NN] [Ag]: searches for words a or g after N or N.
Bytes --------------------------------------------------------------------------------------------------------------
In the character group, hyphens (-) indicate that the range ranges from start to end,
The hyphen '-' is a hyphen only when it appears inside the character group. In other cases, it only indicates the character: "-" has no special meaning.
If the '-' character appears at the first position in the character group or after the character "^" appears in the character group, the character is not a hyphen but only a character.
Example: String num = "012c34a5b! # @ $-% $ ^ % & * & (-) *) & 6fr7gd89 ";
[2-6]: Search for numbers between 2 and 6
[A-R]: Find characters from A to R
[2-6a-r]: searches for characters ranging from 2 to 6 from A to R.
[2-6a-r! @ ^ & *]: Find the characters and! @ ^ & * And other special characters
[-2-6a-r]: searches for characters and-from 2 to 6 from A to R-
Bytes ---------------------------------------------------------------------------------------------------------------
Escape Character: ^: When ^ appears in the first position in the character group, it indicates exclusion, that is, except,
If the escape character is not in the first position of the [] character group, the ^ represents only one character and has no special significance.
[^ 0-9]: searches for characters other than numbers in a string.
[^ 2-6a-r]: searches for all characters in a string other than the number between 2 and 6 and the character between the A-R
[^-2-6a-r]: searches for all characters except the characters between numbers 2 to 6 and between the A-R and "-" in a string (here "-" is just one character, without a hyphen)
Note the following:
String STR = "abcdabcd ";
If the expression: d [^ 0-9] can only match the DA in the string, but cannot match the D at the end, because D at the end has nothing to exclude from the character ^
If we add a space at the end, we can match it.
Bytes -----------------------------------------------------------------------------------------------------------------
Use "." To match any character
For example: 03/19/76 03-19-76 03.19.76 can use 03 [-/.] 19 [-/.] 76. You can also use 03.19.76 to match, but 03.19.76 may also match
03-19a76, because "." can match any character
NOTE: If "." is placed outside the character group, it indicates metacharacters, but if it is placed in the character group, it indicates a common "."