1.3.6 matches multiple strings (2018-05-08)
We used the select match in the regular expression bat|bet|bit (| Symbol The following is a method for using regular expressions in Python.
ImportRe#Select a match (|) symbol in Bat|bet|bitBT ='Bat|bet|bit' #Regular expression pattern: bat, bet, bitm = Re.match (BT,'Bat')#' Bat ' is a matchifM is notNone:Print(M.group ())Print("Match Success")
Run Result: Must be successful match to object
#Select a match (|) symbol in Bat|bet|bitBT ='Bat|bet|bit' #Regular expression pattern: bat, bet, bitm = Re.match (BT,'BLT')#no match for ' BLT 'ifM is notNone:Print(M.group ())Print("Match Success")Else: Print("Match failed")
Run Result: There is no match for ' BLT ', so the result must be a match failure
#Select a match (|) symbol in Bat|bet|bitBT ='Bat|bet|bit' #Regular expression pattern: bat, bet, bitm = Re.match (BT,'He bit me!')#cannot match stringifM is notNone:Print(M.group ())Print("Match Success")Else: Print("Match failed")
Run Result: cannot match string, so must match failed
#Select a match (|) symbol in Bat|bet|bitBT ='Bat|bet|bit' #Regular expression pattern: bat, bet, bitm = Re.search (BT,'He bit me!')#find ' bit ' through searchifM is notNone:Print(M.group ())Print("Match Success")Else: Print("Match failed")
Run Result: Search for ' bit ', so the result is a successful search
1.3 Regular expressions and Python language -1.3.6 match multiple strings