Regular expression is a logical formula for string operation , It is to use some specific characters defined in advance 、 And the combination of these specific characters , Form a “ Rule string ”, To filter out the content that meets this rule .
It can be simply understood as : A powerful search tool , A regular expression is a conditional expression for what you want to search .
effect : Traversing the entire string , You can get all the matching strings , Return a list .
General usage :
re.findall(r' Regular expressions ',' Text to match ')
import re
text = "0537-146987425,0537-299656897,The moment you think about giving up,think of the reason why you held on so long. Total umbrella for someone else if he, you’re just not for him in the rain.Never put your happiness in someone else’s hands.Sometimes you have to give up on someone in order to respect yourself. aaaa bbbbcc d dddddd"
print(re.findall(r'to',text))
['to', 'to']
print(re.findall(r'\bg\w*?\b',text))
['giving', 'give']
print(re.findall(r'\b\w{4}\b',text))
['0537', '0537', 'held', 'long', 'else', 'just', 'rain', 'your', 'else', 'have', 'give', 'aaaa']
print(re.findall(r'\d{4}-\d{8}',text))
['0537-14698742', '0537-29965689']