How can I remove the alphabets and show the numbers only in a label expression of a layer?

For example, I have a field with values: TK209, 01TKRW394, 045TK, 089EYZ46 and I want to display labels as: 209, 01394, 045, 08946 respectively.

1 Answer 1


You can filter the string by digits using str.isdigit method. Change [Key] to the name of your field:

def FindLabel ( [Key] ):
  return filter(str.isdigit, str([Key]))

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.