A regular expression is a string of characters that contain special meanings, which are called metacharacters in regular expressions. For example, "\\dhello" in the \\d is a special meaning of the meta-character, representing any of the 0~9. Both the string "9hello" and "1hello" are one of the strings that match the regular expression "\\dhello".
(1) The string object calls the public Boolean matches (string regex) method to determine whether the current string object matches the regular expression specified by the parameter regex;
(2) Common metacharacters and its significance are as follows:
(3) In a regular expression, you can enclose several characters in square brackets to represent metacharacters, which represent any one character in square brackets. For example regex= "[159]abc", then "1ABC", "5ABC", "9ABC" are strings that match the regular expression regex.
[ABC]: Represents any of a, B, C;
[^ABC]: represents any one character except A, B, C and foreign;
[A-za-z]: represents any one of the English letters;
[A-d]: represents any one of the a-d;
[A-d[m-p]]: Represents a to D, or M to p any character (and);
[A-z&&[def]]: represents any of the D, E, F (intersection);
[A-F&&[^BC]: Represents a, D, E, f (difference)
(4) The qualifier modifier can be used in regular expressions. For example, using the qualifier modifier:?, if x represents a metacharacters or ordinary character in a regular expression, then X? means x appears 0 or 1 times, for example:
regex= "a[2468", "A", "A2", "A4", "A6", "A8" are all strings that match the regular expression regex.
Common qualifier modifiers are used as follows:
(5) The regular expression use case is as follows:
Summary of Java regular expression knowledge points