Recently, due to work needs, I read "regular expression must know" again. This is a small book that will soon be completed. I have a deeper understanding of regular expressions, which is indeed very powerful and worth learning.
The results are summarized as follows:
Two purposes of a regular expression: Search and replacement
. Match any single character [] Character Set combination Interval -Hyphens ^ Do not match
Special metacharacters: [\ B] rollback \ F page feed \ N linefeed \ R carriage return \ T Tab \ V vertical Tab \ D any number character [0-9] \ D [^ 0-9] \ W [a-zA-Z0-9 _] \ W [^ a-zA-Z0-9 _] \ S [\ f \ n \ r \ t \ v] \ S [^ \ f \ n \ r \ t \ v] + Match one or more characters * Matches zero or multiple characters. ? Matches zero or one character {N} exact match appears n times {N, m} exact match n to m times {N,} matches at least N times The above methods are greedy, as long as one is added after ?, Become lazy Limits: \ B specifies the word boundary \ B specifies not the word boundary ^ Starts with a string $ End of string ? M. The sequence of metacharacters that change the behavior of other metacharacters must appear at the beginning of the entire mode. \ N backtracking reference $1 replacement with backend reference ? = Forward search,? = Indicates the child expression starting with ", that is, whether the final content exists in the matching range ." ? <= Backward Search ?! Negative forward lookup, backward lookup does not match ? <! Negative backward lookup, backward lookup does not match Regular Expression Conditions: ? (Backreference) True-RegEx), where? This indicates that this is a condition. The backreference in parentheses is expressed by a number, representing the subexpression that will be executed only when the backreference exists. ? (Backreference) True-RegEx | false-RegEx) Common Regular Expressions: URL: HTTPS? : // [-\ W.] + (: \ D + )? (/([\ W/_.] *)? Complete URL: HTTPS? : // (\ W *: \ W *@)? [-\ W.] + (: \ D + )? (/([\ W/_.] * (\? \ S + )?)?)? Email Address: (\ W + \.) * \ W + @ (\ W + \.) + [A-Za-Z] +