0

I have road ID labels in a string field that need to be parsed down. I'm using the python advanced label expression. I've removed the preceding '0s' successfully as well as some known text.

I need to remove all other preceding alpha characters prior (left of) to the number but keep any alpha characters after (right of) the number. The amount of characters vary so I can not use [:3] etc.

This code snippet removes ALL alpha, not just at beginning:

enter image description here

This snippet shows verified but does not yield any labels:

enter image description here

What is your syntax suggestion?

I've also tried lstrip()[0].isalpha() can't get that to work either.

1 Answer 1

1

A recursive solution might work. Something like:

def FindLabel(label):
    if label[0].isalpha():
        FindLabel(label[1:])
    return label

Which would be called with FindLabel([ID])

2
  • I got the syntax correct by adding label = ( [ID] ) and it verifies but no labels are returned. def FindLabel ( [ID] ): label = ( [ID] ) if label[0].isalpha(): FindLabel([ID][1:]) May 27, 2020 at 15:58
  • UPDATE: I've got the label syntax to work correctly but ONLY for the letter 'A' new syntax is: def FindLabel ( [ID] ): label = ( [ID] ) if label[0].isalpha(): return [ID].lstrip('A - Z') May 27, 2020 at 16:11

Your Answer

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

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