In Java programming thought, the \\ expression "I want to insert a backslash in a regular expression, so the character behind it has a special meaning." "If you want to insert a normal backslash, you should use it \\\\ ."
Understand:
The backslash that we use is a\
But in programming languages like Java, we need to use escape: A literary backslash \\ represents a normal backslash\
In regular expressions, backslashes also need to be escaped, that is, to \\ match one \ , and then the egg hurts, and when you write in Java \\ , the regular expression engine only accepts one \ , so if you want the regular expression engine to accept two backslashes, Then both of these slashes must be escaped.
So, the regular expression matches a \ yes, should write\\
At this point, the first one \ in the Java string is written as\\
The second one is \ written in the Java string as\\
So, you see, in Java, the egg hurts.\\\\
Common Regular Expressions:
1, character
b Specifies the character B
\XHH characters with hexadecimal value 0xhh
\uhhhh hexadecimal representation of Unicode characters as 0xhhhh
\ t Tab tab
\ n Change the character
\ r Enter
\f Page Change
\e Escape (Escape)
2. Character class
. Any character
[ABC] contains any character of a, B, and C (same as A|b|c action)
[^ABC] Any character except A, B, and C (negation)
[A-za-z] any character (range) from A to Z or from A to Z
[Abc[hij]] any A, h, I, and J characters (same as A|B|C|H|I|J) (consolidated)
[A-z&&[hij]] arbitrary H, I or J (cross)
\s Whitespace (Space, tab, line feed, page feed, and carriage return)
\s non-whitespace characters ([^\s])
\d Number [0-9]
\d non-digital [^0-9]
\w word character [a-za-z0-9]
\w non-word characters [^\w]
3. Logical operators
XY y followed by x
X| Y x or Y
(X) capturing group, which can be used in expressions to represent the \i capturing group
4. Boundary Match character
^ Start of a line
End of the $ line
The boundary of the \b Word
\b Boundaries of non-words
\g the end of a previous match
5. quantifier
How to match the greedy type of the possessive type
X? X?? x?+ of one or 0 x
x* x*? x*+ of 0 or more X
x+ x+? X + + one or more ×
X{n} x{n}? X{n}+ exactly n times x
X{n,} x{n,}? x{n,}+ at least n times x
X{n,m} x{n,m}? x{n,m}+ x at least n times, and not more than m times
Regular Expressions in Java