1.3.7 matches any single character (2018-05-08)
point number (. Cannot match a newline character \ n or a non-character, which means an empty string
search for a real period (decimal point) While we are using a backslash to escape the function of a period:
ImportRe#The dot (.) cannot match a newline character \ n or a non-char, that is, an empty string. Anyend ='. End'm= Re.match (Anyend,'Bend')#dot number matches ' B 'ifM is notNone:Print("Match Success") Print(M.group ())Else: Print("Match failed")
Run result: Dot matches ' B ' match success
#The dot (.) cannot match a newline character \ n or a non-char, that is, an empty string. Anyend ='. End'm= Re.match (Anyend,'End')#does not match any charactersifM is notNone:Print("Match Success") Print(M.group ())Else: Print("Match failed")
Run Result: Mismatched any character match failed
#The dot (.) cannot match a newline character \ n or a non-char, that is, an empty string. Anyend ='. End'm= Re.match (Anyend,'\nend')#any character other than \ nifM is notNone:Print("Match Success") Print(M.group ())Else: Print("Match failed")
Run Result: any character match except \ n failed
#The dot (.) cannot match a newline character \ n or a non-char, that is, an empty string. Anyend ='. End'm= Re.search (Anyend,'The end.')#match "in Search"ifM is notNone:Print("Search Success") Print(M.group ())Else: Print("Search Failed")
Run Result: Match "search success in Search"
#search for a real period (decimal point), and we escaped by using a backslash for the function of the period:patt314 ='3.14' #the point number that represents the regular expressionPi_patt ='3\.14' #the dot number that represents the literal (Dec. Point)m = Re.match (Pi_patt,'3.14')#Exact Match 3.14ifM is notNone:Print("Match Success") Print(M.group ())Else: Print("Match failed")
Run Result: Exact Match 3.14 match succeeded
#search for a real period (decimal point), and we escaped by using a backslash for the function of the period:patt314 ='3.14' #the point number that represents the regular expressionPi_patt ='3\.14' #the dot number that represents the literal (Dec. Point)m = Re.match (patt314,'3014')#dot number match ' 0 'ifM is notNone:Print("Match Success") Print(M.group ())Else: Print("Match failed")
Run Result: Dot match ' 0 ' match succeeded
#search for a real period (decimal point), and we escaped by using a backslash for the function of the period:patt314 ='3.14' #the point number that represents the regular expressionPi_patt ='3\.14' #the dot number that represents the literal (Dec. Point)m = Re.match (patt314,'3.14')#match dot number '. 'ifM is notNone:Print("Match Success") Print(M.group ())Else: Print("Match failed")
Run Result: Dot match '. ' Match succeeded
#search for a real period (decimal point), and we escaped by using a backslash for the function of the period:patt314 ='3.14' #the point number that represents the regular expressionPi_patt ='3\.14' #the dot number that represents the literal (Dec. Point)m = Re.match (patt314,'3S14')#dot number match ' s 'ifM is notNone:Print("Match Success") Print(M.group ())Else: Print("Match failed")
Run Result: Dot match ' s ' match succeeded
1.3 Regular expressions and Python language -1.3.7 match any single character