Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a field containing alphanumeric values in the following format:


Sometimes they are also


I need a Python script I can put in the field calculator in ArcMap 10 that will at least remove the numeric characters, and retrain the alphabetical ones and the hyphen. So that, for example, this:


becomes this:


I also want to replace the numeric chars with numeric chars from another field. This Stack Exchange entry addresses this issue, but the string has a space before the number and this can be used for splitting and indexing... my strings are not so handily constructed.

share|improve this question
up vote 14 down vote accepted

I would use regular expressions. If you put the following in the code block section of the calculator it will return a string that has all digits stripped, no matter were they are:

import re
def strip_digits(s):
    return re.sub("\d+", "", s)

This can then be called from the calculate box as:


If you want to replace characters, add another argument to the function for the replacement characters, and put it in place of the empty string.

share|improve this answer
absolutely!, you want regex to handle these character parsing issues. – Brad Nesom Jan 11 '12 at 14:23
I added a link to the regular expressions how-to in the Python docs for the uninitiated. – blah238 Jan 11 '12 at 18:39
Thanks for that @blah238 – om_henners Jan 11 '12 at 21:59

just use strip

print s.strip("0, 1,2,3,etc")
share|improve this answer

I also found this in the mapping center (
resources center text management tool

It is old code written for 9.2/9.3. Not sure about appropriateness for 10.x The description reads...

  1. Batch Find and Replace: This tool populates strings in a text field with replacement strings that are specified in a Find/Replace table. This is useful for standardizing label strings or introducing and enforcing standard abbreviations.
  2. Convert Text to Proper Case: This tool converts the text strings in one field (presumed to be all upper or all lower case) to a proper case (mixed upper and lower case) text string in another (new) field. This tool is written to handle common abbreviations such as NE for northeast, so that it won't come out as Ne.
  3. Extract Hwy Numbers for Hwy Shield Labels: Adds the numeric portion of a highway name to another text field.

All these tools are written in Python and can be modified to accomplish any specific needs you have.

share|improve this answer

I would start with this simple case:

>>> x = "A-AA00"
>>> print x
>>> print x.replace("0","")

From there some of the codeblock examples for Python from the ArcGIS 10 Help should give you a headstart to the total solution.

share|improve this answer
I think the problem with this is that there's no easy way to handle non-0 digits. That's why regular expressions are so useful, as om_henners pointed out. – nmpeterson Jan 11 '12 at 16:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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