Sandhya Prabhakaran <sandhyaprabhaka...@gmail.com> writes: > Hi, > > I have a string as str='123ACTGAAC'. > > I need to extract the numeric part from the alphabetic part which I > did using >>>>numer=re.findall(r'\d+',str) >>>>numer > 123 > > To get the alphabetic part, I could do >>>>alpha=str.replace('123','') >>>>alpha > ACTGAAC > But when I give >>>>alpha=str.replace(numer,'') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: expected a character buffer object > > How do I blank out the initial numeric part so as to get just the > alphabetic part. The string is always in the same format.
Firstly, you really should read the Regular Expression HOWTO: http://docs.python.org/howto/regex.html#regex-howto Secondly, is this what you wanted to do? >>> p = re.compile(r'^\d+') >>> p.sub('', '123ACTGAAC') 'ACTGAAC' Regards, Peter -- Peter Brett <pe...@peter-b.co.uk> Remote Sensing Research Group Surrey Space Centre -- http://mail.python.org/mailman/listinfo/python-list