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 ([])