Using ArcGIS Data Reviewer on top of ArcMap 10.5, I am trying to write a regular expression in table checks that will only allow 5 characters or Less in a field otherwise the value should be reported as an error.

For Example:

abcDe value is ok

abc value is ok

AB value is ok

abcdefg value is NOT ok

What I have so far looks like this:


Unfortunately this is not working (returns all the values in the attribute table) since data reviewer doesn't handle {} "Curly brackets"

What other options might I have i.e. how do I set a regular expression that returns the unmatched values if the characters exceeded a certain length.

@ahmadhanb provided Python script that works fine in Field calculator.

But I am looking forward doing this in Data Reviewer R.E as a part of batch checks, unfortunately DR doesn't take python scripts.

enter image description here

The Script provided by ahmadhanb:

def check(f):
  import re
    pattern = re.compile(r"[A-Za-z][A-Za-z]-[A-Za-z][A-Za-z]-(\w+)-([A-Za-z]
    match = pattern.search(f)
    id = match.group(1)
    if len(id) <= 8:
        return "Valid"
        return "Project Name more than 8 Characters"
        return "Project ID Doesn't match the Expression"
  • Why don't you use (Execute SQL check) to check and validate the field length?
    – Moh
    Mar 20, 2018 at 16:05
  • 1
    Good point, I didnt because this issue is a part of larger R E check, the main problem is with this part only. I am checking project ID's that looks like "qw-rf-abcde-uyt", the main issue is with this part "abcde" which could be 5 characters or less in some checks, and 10 or less in some checks, I have included this small part just to make it easier for the community to see where the problem is. Thank you though for you input. Mar 20, 2018 at 17:50

1 Answer 1


You can add a new field in the attribute table to check whether the ID field has a valid ID or not using regular expression (RE) as follows:

def check(f,v):
    import re
    pattern = re.compile(r"\w+-\w+-(\w+)-\w+")
    match = pattern.search(f)
    id = match.group(1)
    if len(id) <= 5:
        return "Valid"
        return "Invalid"

You can use the code above in the new added field using Field Calculator, and it will extract the group(1) - because group(0) means the whole text - which is the portion of the ID that you want to check, and if the number of characters less than or equal to 5 characters, it will return Valid, otherwise it will return Invalid ID.

Here is the test ID1 column and the results in the Check column.

enter image description here

  • Thanks Ahmad for the answer, I didnt know that RE can be used in Python, the script worked perfectly and I added some enhancements on it as the following: def check(f): import re try: pattern = re.compile(r"[A-Za-z][A-Za-z]-[A-Za-z][A-Za-z]-(\w+)-([A-Za-z][A-Za-z][A-Za-z])") match = pattern.search(f) id = match.group(1) if len(id) <= 8: return "Valid" else: return "Project Name more than 8 Characters" except: return "Project ID Doesn't match the Expression" Mar 21, 2018 at 16:08
  • @Ahmadsaleh You are welcome. RE module is one of the powerful modules in python. It is unfortunate that Data Reviewer extension doesn't have python, and I am not sure if anyone can help you to solve your problem as DR extension is not commonly used. Anyway, I hope someone can assist you to find a solution.
    – ahmadhanb
    Mar 21, 2018 at 19:21

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.