AnsweredAssumed Answered

Remove letters and special characters from an alpha numeric string using python

Question asked by jessicakirby on Nov 15, 2012
Latest reply on Feb 28, 2019 by ehmesri
Hi All,
I need to find a way to remove all letters and special characters from a string so that all i am left with is numbers using python.
The end goal is to use this code in the python code block in the Calculate Field GP tool.

I have a field called Lease_Num
It contains a string such as ML-26588 , ML 25899, UTLM58778A
So sometimes it has a dash, sometimes it has a space and sometime it has nothing.  The Alpha characters can be any length and the numbers can be any length.  Sometime their can even be an alpha character at the end of the string...its totally random

I need to strip out the the alpha's and any special characters or spaces from the string to leave me with just the number.

Can someone help me with how I would do this and then tell me how to apply it to the code block on Calculate Field GP tool.

Many thanks!