1

How do I write an advanced labeling expressions to only show a part of a string?

I want my data that looks like this EVA007 only to show the 007 part.

1
  • 2
    What's the rule for your labeling? Is it cutting the frist three letters? Or cutting everything except numbers?
    – Mesa
    Aug 2 '18 at 8:59
3

If you want to cut the first three letters, you can use the following Python expression (set option "advanced" expression):

def FindLabel([NAME]):
  return [NAME][3:]

If you want to keep the last three characters (numbers in your case) instead of cutting the first three, change [3:] to [:-3].

1
  • Worked perfectly!
    – GIS_Eva
    Aug 2 '18 at 9:56
1

Based on the VB script, the solution could be

Right([FIELDNAME], 3)

or

Replace([FIELDNAME], "EVA", "")
0

Another solution, if you wanted to remove the alphabets and show the ending numbers only:

import re
def FindLabel ( [FIELDNAME] ):
  p = re.search('[0-9]+', [FIELDNAME])
  if p is None:  
   return [FIELDNAME]
  else:  
   return p.group(0).replace('(','')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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