Greedy mode and non-greedy mode of quantitative words
Regular expressions are typically used to find matching strings in text. The number of words in Python is greedy by default (which may be the default non-greedy in a few languages), always trying to match as many characters as possible, and not greedy, instead, always trying to match as few characters as possible. For example: the regular expression "ab*" will find "abbb" if it is used to find "ABBBC". And if you use a non-greedy quantity word "ab*?", you will find "a".
Re.compile ()
>>> exp = re.compile ("[A-z]") # generates a regular object to match >>> m = Exp.match ('bigtext') print(M.group ()) b
Matching IP
" 192.168.0.1 " = Re.match ("([0-9]{1,3}\.) {3}\d{1,3}", String)print(M.group ())
Match phone number
# Match Phone number "Hey My name is Zhangsan, and my phone number is 13651053467"" Hey my name is Zhangsan, and my phone number is 15811784456"= Re.search ("(1) ([35 87]\D{9})", Phone1) # The first group matches the first number, the second group matches the second number, and the third group matches the remaining 9 digits
Python (5)-Regular expression