Speak quietly, the daughter is not beautiful
I haven’t updated the article for a long time, mainly because I don’t know how to write it. Recently, I have been busy with security development, and many of my knowledge has been temporarily stagnant, so there is no new knowledge to share. I remember that I was asked how to write regular expressions. I will combine the Python language in this article to summarize how regular expressions should be written.
If you want to write a regular expression, learn the rules first!
It is important to note that regular matching defaults to greedy matching, which means matching as many characters as possible.
Note: Since \d+ uses greedy matching, all the following 0s are directly matched, and the result 0* can only match the empty string. You must let \d+ use a non-greedy match (that is, as few matches as possible) to match the next 0, plus one? Let \d+ use a non-greedy match:
It is recommended to test the quality of the regularity before using the regularity in the code. For the convenience of use, I wrote an online tool that I can use: http://tool.nmask.cn/python_re/