Preface
Usage scenarios:
1. Check the validity of the data
2. Find text that meets the requirements and perform operations such as cutting and replacing the text
Commonly used knowledge points are listed below:
Metacharacters
Concept: refers to special characters with special meanings in regular expressions
Special single character
. Any character
Example:
\d represents a number \D represents a non-digit
\w Numbers and letters underline \W negate
\s whitespace character \S negate
Extend other whitespace characters
quantifier
Meaning: The single characters and whitespace characters mentioned above can only match single characters. When you need to match multiple things, you need to use quantifiers.
scope
It is needed when special single characters cannot meet the needs.
Make a common exercise based on these: match mobile phone number
1, 11 digits
2, the first digit starts with 1
3, the second digit may be 3, 4, 5, 6, 7, 8, 9;
Group
When there are multiple metacharacters that make up a part and should be treated as a whole, you need to wrap it with ()
Another question:
Matches those starting with http:// https:// or ftp://
Matching patterns and escaping
Case insensitive
(?i) cat
When special single characters are to be matched correctly, they need to be escaped with \
affirmation
Solving word boundary problems
Extension regarding performance issues
https://jishuin.proginn.com/p/763bfbd69152
at last
Although regular expressions are good, they need to be used with caution, especially when searching in large text.