1.3 Regular expressions and Python language -1.3.6 match multiple strings

Source: Internet
Author: User

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

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.