Python @ DjangoSpin

PyPro #64 Obtain numbers from an alphanumeric string

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Obtain numbers from an alphanumeric string in Python

Obtain numbers from an alphanumeric string in Python

Obtain numbers from an alphanumeric string. Write a Regular Expression in Python to obtain a list of numbers from a string containing alphanumeric characters.

Obtain numbers from an alphanumeric string

import re

sourceString = '1a2b3c4de5f6'

print( re.split('[a-zA-Z]+', sourceString) )		# ['1', '2', '3', '4', '5', '6']

To learn more about Regular Expressions in Python, click here.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply