AnsweredAssumed Answered

Field calculator - regular expressions

Question asked by malauch on Sep 25, 2017
Latest reply on Sep 25, 2017 by bharold-esristaff

Hi,
I'm beginner in ArcGIS Pro (I just switched from QGIS) and have some problem with some a little more advanced operation in field calculator. I would like to know how to use REGEX in field calculator to extract particular part of the string.

 

The string if in "Adr_for" field and in field "Number" I want to have extracted part.

 

Examples of the strings in "Adr_for":
13-0222222-1-02226-249A - -
13-022222-1-02225-33 - -

 

Expected result in "Number":
249A
33

 

Regex expression (which worked in QGIS):
((\d+(?!(\d|-))\w)|(\d+(?!(\d|-))))

 

I tried to use something like this in ArcGIS PRO field calculator but it didn't work.

 

Expression:
regex(!Adr_for!)

 

Code Block:
import re
def regex(Adr_for):
    return re.search(r"""((\d+(?!(\d|-))\w)|(\d+(?!(\d|-))))""", Adr_for)

 

How should I do this to achieve expected result?

Outcomes