python learning, day5: Regular

# Coding. 8 = UTF- 
# the Author: Ryan of Bi 
Import Re 

RES = re.match ( ' Ryan ' , ' Ryan123abcdefg456 ' )    # match two similar string part 
Print (RES)
 Print (res.group ())     # to display only those portions 

RES1 = re.match ( ' Ryan \ D ' , ' Ryan123abcdefg456 ' ) # behind the display matching digital 
Print (RES1) 
RES2 = re.match ( ' Ryan \ + D ' , ' Ryan123abcdefg456' ) # Behind the display matches all numbers 
Print (RES2) 
RES3 = re.match ( ' ^. ' , ' Ryan123abcdefg456 ' ) # ^ meaning the beginning (match from scratch), [^] represent non meaning. in addition to a \ any outside a character n (this is to take the beginning character) 
Print (RES3) 
RES4 = the re.search ( ' B. + e ' , ' Ryan123abcdefg456e ' ) # Search to the beginning b, e end of characters intermediate 
Print (RES4) 
Res5 = the re.search ( ' A [AZ] + G ' , ' Ryan123abcdefgAbcdefg456e ' ) #Take a beginning, end g, az of the intermediate string 
Print (Res5) 
res6 = the re.search ( ' a [a-zA-the Z] + G ' , ' Ryan123abcdefgAbcdefg456e ' ) # take a beginning, end g, the middle az and AZ string 
Print (res6) 
Res7 = the re.search ( ' #. # + ' , ' 123 Hello # # ' ) # between two # 
Print (Res7) 
res8 = the re.search ( ' a? ' , ' aabce ' ) # belt? ,match? Before the character 0 or 1 times 
Print (res8) 
Res9Re.search = ( ' AAL? ' , ' Aabceaaa ' ) # belt? ,match? Before character 0 or 1 times (L times is 0, that is, matching AA) 
Print (Res9) 
res10 = the re.search ( ' [0-9]. 3} { ' , ' aab1c2e3456a5aa ' ) # match 0-9 consecutive 3 
Print (res10) 
Resll = the re.findall ( ' [0-9] l, 3} { ' , ' aab1c2e345a5aa ' ) # match 0-9, 1-3 consecutive, all matched to 
Print (Resll) 
Resll re.search = ( ' abc | ABC ', ' AbcddABC ' ) # | meaning or 
Print (Resll) 
res12, = re.findall ( ' abc | ABC ' , ' abcddABC ' ) # | or mean findAll 
Print (res12,) 
Resl3 = re.search ( ' ABCD \ | ' , ' ABCD | DABC ' ) # | pipe characters match 
Print (Resl3) 
res14 = the re.search ( ' \ A [0-9] + [AZ] \ the Z ' , ' 123a ' ) # \ beginning A, \ Z end, equivalent to $
Print (res14) 
res15 = the re.search ( ' \ + D ' , ' 123a, ' ) # \ D non-digit \ W matches non-alphanumeric, \ W matching alphanumeric, \ matching whitespace 
Print (res15) 
Res 16 = Re. Search ( ' (? P <ID> [0-9] +) ' , ' abde1234afd @ 13 is ' ) .groupdict () # \ D non-digit \ W matches non-alphanumeric, \ W matching alphanumeric, \ match whitespace 
Print (Res 16) 
res17 = the re.search ( ' (? P <ID> [0-9] +) (? P <name> [AZ] +) ' , ' abde1234afd @ 13 is ' ) .groupdict () # direct matching to dictionary
Print (res17)
 Print (res17 [ ' ID ' ]) 
res18 = the re.search ( ' (? P <Provice> [0-9] {}. 4) (? P <City> [0-9] {2}) (? P <Birthday> [0-9] {}. 4) ' , ' 130603197911010318 ' ) .groupdict ()
 # take identification number 
Print (res18) 
Res 19 = re.split ( ' [0-9] + ' , ' abd124dedg8dsf ' ) # at intervals figure is formed list 
Print (Res 19) 
res20 = the re.sub ( ' [0-9] + ' , '|', ' Abd124dedg8dsf ' ) # digital replaced | 
Print (res20) 
RES21 = the re.search ( ' [AZ] + ' , ' abdEDFGE8dsf ' , the flags = re.I) # the flags = re.I, ignore case 
Print ( RES21) 
res22 = the re.search ( ' [AZ] + $ F ' , ' ABD \ nEDFG \ nE8dsf ' , the flags = re.M) # the flags = re.M, even with the wrap, can be matched 
Print (res22) 
res23 the re.search = ( ' . $ F + ' , ' ABD \ nEDFG \ nE8dsf ', flags = re.S) # theoretically match flags = re.S addition newline \ n, but not windows 
Print (res23) 
res24 = the re.search (R & lt ' \ D + \.? \ D * ( \ * -?.? \ d + \ \ d *) + ' , 2 * 2 )
 Print (res24)

 

Guess you like

Origin www.cnblogs.com/bbgoal/p/11890524.html