Regular expressions have a lot of content, are also very flexible and powerful, and must be recorded and summarized.
01-Common methods and common problem records of regular expressions of Python's re module for beginners
链接1:https://blog.csdn.net/wenhao_ir/article/details/125960370
链接2:https://blog.csdn.net/wenhao_ir/article/details/125921141
02- What is the difference between + and * in regular expressions?
https://blog.csdn.net/wenhao_ir/article/details/131289181
03-What is the function of the compile() method of Python's regular expression re module?
https://blog.csdn.net/wenhao_ir/article/details/132026895
04-What do the symbols ^ and $ in regular expressions mean and what are they used for?
The symbol ^ means to start matching from the beginning of a string, and the symbol $
means to start matching from the end of a string, for example, the regular expression hello$
will match the string ending with "hello".
Combined with ^
and $
, you can ensure that the regular expression must match completely within the entire string.
As an example, suppose you have the following list of strings:
strings = ["hello world", "world hello", "hello", "hello world again"]
If we use a regular expression hello
to match, it will match all strings that contain the substring "hello":
- “hello world”
- “world hello”
- “hello world again”
But if we use a regular expression ^hello$
to match, it will only match the string whose entire string content is "hello", that is, only the string "hello" will be matched.
04-What is the use of parentheses in regular expressions?
It is usually used to make the logic clearer, such as in regular expressions matching mobile phone numbers in mainland China:
regular expressions with brackets:
r'^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$'
than the regex without parentheses:
r'^13[0-9]|15[012356789]|17[678]|18[0-9]|14[57][0-9]{8}$'
It is logically clearer and avoids the effect of looking at a sticky cake.
05-What is the use of square brackets [] in regular expressions?
Link: https://blog.csdn.net/wenhao_ir/article/details/132028092
06- Curly Braces in Regular Expressions - What is the use of curly braces {}?
Link: https://blog.csdn.net/wenhao_ir/article/details/132028331