ezoic

Wednesday, May 18, 2016

A python regular expression matching number group

aa='Wicked Tuna SSN 5  NGG'
aa=re.sub(r'NGC','',aa)
aa=re.sub(r'NGG','',aa)
match1=re.match(r'(.*) SSN (\d+)',aa)
match2=re.match(r'(.*) S(\d+)', aa)
if match1:
        aa=match1.group(1)+' '+'Season'+' '+match1.group(2)
 
if match2:
        aa=match2.group(1)+' '+'Season'+' '+match2.group(2)
print aa

Returned value:

Wicked Tuna Season 5

No comments:

Post a Comment

looking for a man

 I am a mid aged woman.  I was born in 1980. I do not have any kid. no complicated  dating before . I am looking for a man here for marriage...