June 1, 2019 Happy Children's Day re module 3

Import Re 
ret19 = the re.findall ( ' (ABC) + ' , ' abc2abc4abc ' ) # findAll string is to put all the results of the matches in the list 
Print (ret19) # in parentheses indicate the composition of a whole 
ret20 = re.search ( ' (? P <name> \ w +) ' , ' abcccc ' ) # famous group, <name> wrote later need to match the content here is \ W +, searh is to find a satisfying is no longer looking back. 
Print (ret20.group ()) 
Ret21 = the re.search ( ' \ + D ' , ' aba442dfa14 ' )
 Print (ret21.group ()) #Match value achieved by the Group 
ret22 the re.search = ( ' (? P <name> [AZ] +) \ + D ' , ' sxj30abc22def33 ' )
 Print (ret22.group (), ret22.group ( ' name ' )) # for packet, meaning that the group name, and then directly read the packet group 
Ret23 the re.search = ( ' (? P <name> [AZ] +) (? P <Age> \ + D) ' , ' alex30abc22def33 ' )
 Print (ret23.group (), ret23.group ( ' name ' ), ret23.group ( ' age ' )) # the name and age are expressed packet

》》》

['abc', 'abc', 'abc']
abcccc
442
sxj30 sxj
alex30 alex 30

Guess you like

Origin www.cnblogs.com/python1988/p/10960796.html