1.3 Regular expressions and Python language -1.3.8 creating character sets ([])

Source: Internet
Author: User

1.3.8 Create character set ([]) (2018-05-0815:24:00)

  The following example shows restrictions on R2D2|C3PO will be stricter than [Cr][23][dp][o2]

ImportRe#The following example shows that the limit for R2D2|C3PO will be stricter than [CR][23][DP][O2]m = Re.match ('[Cr][23][dp][o2]','C3PO')#match ' C3PO 'ifM is  notNone:Print(M.group ())Print("Match Success")Else:    Print("Match failed")

Run Result: Match ' C3PO ' match succeeded

m = Re.match ('[Cr][23][dp][o2]','c2do')#match ' c2do 'ifM is  notNone:Print(M.group ())Print("Match Success")Else:    Print("Match failed")

Run Result: Match ' c2do ' match succeeded

m = Re.match ('R2D2|C3PO','c2do')#does not match ' c2do 'ifM is  notNone:Print(M.group ())Print("Match Success")Else:    Print("Match failed")

Run result: Mismatched ' c2do ' match failed

m = Re.match ('R2D2|C3PO','R2D2')#match ' R2D2 'ifM is  notNone:Print(M.group ())Print("Match Success")Else:    Print("Match failed")

Run Result: Match ' R2D2 ' match succeeded

1.3 Regular expressions and Python language -1.3.8 creating character sets ([])

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.