Extract the numeric and alphabetic part from an alphanumeric string

Sandhya Prabhakaran sandhyaprabhakaran at gmail.com
Mon Aug 3 18:52:48 CEST 2009


Oh yes indeed........!
Now that works :D

Thanks a lot !!

2009/8/3 Kushal Kumaran
<kushal.kumaran+python at gmail.com<kushal.kumaran%2Bpython at gmail.com>
>

> On Mon, Aug 3, 2009 at 8:47 PM, Sandhya
> Prabhakaran<sandhyaprabhakaran at gmail.com> wrote:
> > 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
> >
>
> The docs for re.findall say that it returns a list of matches.  So
> '123' will be numer[0].
>
> > 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
> >
>
> That's what would happen if you pass in a list instead of a string to
> replace.
>
> > 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.
> >
> > Please help.
> >
>
> --
> kushal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090803/c5cee078/attachment.html>


More information about the Python-list mailing list