2017-04-03 28 views

答えて

1
test = ['staaaap', 'nomatchaaaaabbbb', 'matchyaaaabbb'] 

for s in test: 
    m = re.match(r'(?!.*bbbb.*).*aaaa.*', s) 
    if m: 
     print('{} match: {}'.format(s, m.group(0))) 
    else: 
     print('{} no match'.format(s)) 

出力:(?!。* BBBB)。

staaaap match: staaaap 
nomatchaaaaabbbb no match 
matchyaaaabbb match: matchyaaaabbb 
関連する問題