Extract the numeric and alphabetic part from an alphanumeric string
peter at peter-b.co.uk
Mon Aug 3 17:31:09 CEST 2009
Sandhya Prabhakaran <sandhyaprabhakaran at gmail.com> writes:
> I have a string as str='123ACTGAAC'.
> I need to extract the numeric part from the alphabetic part which I
> did using
> To get the alphabetic part, I could do
> But when I give
> 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:
Secondly, is this what you wanted to do?
>>> p = re.compile(r'^\d+')
>>> p.sub('', '123ACTGAAC')
Peter Brett <peter at peter-b.co.uk>
Remote Sensing Research Group
Surrey Space Centre
More information about the Python-list