1.3 Regular expressions and Python language -1.3.7 match any single character

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.