Corrected an error yesterday I used match this only matches the first one with matches to match all the regular expression characters
4. The inverse of the character class
- [^a] means matching any characters that are not "a"
- [^a-za-z0-9] means matching any character that is not a letter or a number
- [\^ABC] matches a character that is "^" or a or B or C
- [^\^] means matching any characters that are not "^"
5. Escape character class
How to shorten the length of regular expression effectively?
- \d = [0-9] Functions the same, all matching any one number. (Regular expression \\d should be used to match \d)
- \d = [^0-9] has the same function, which means matching a non-numeric character.
- \w = [0-9a-za-z] has the same function, which means matching a number or alphabetic character
- \w = [^0-9a-za-z] has the same function, which means matching a non-numeric character that is not a letter at the same time.
- \s means matching a null character (space, tab, carriage return or line break)
- \s indicates that a non-null character is matched.
6. Repeat
After a character or character set, you can use the {} brace to represent a duplicate
- The regular Expression A{1} is the same as a meaning that all matches the letter A
- A{3} indicates a match string "AAA"
- A{0} indicates a match to an empty string. Judging from the regular expression itself, it is meaningless. If you perform such a regular expression on any text, you can navigate to where the search starts, even if the text is empty.
- A\{2\} indicates a match string "a{2}"
- In character classes, curly braces have no special meaning. [{}] means matching a left curly brace, or a right curly brace
Example
z.......z = z.{7}z
\d\d\d\d-\d\d-\d\d = \d{4}-\d{2}-\d{2}
[aeiou][aeiou][aeiou][aeiou][aeiou][aeiou] = [aeiou]{6}
Note: Repeated characters are not memory, such as [abc]{2} means match "A or B or C", and then match "A or B or C", and match "AA or AB or AC or BA or BB or BC or CA or CB or CC". [ABC] {2} does not indicate a match for "AA or BB or cc"
Regular Expression Learning notes (ii)