I have a field titled
GEOGRAPHY, which contains hundreds of records containing various strings of all similar format, for example:
"Witless Bay (1001559) T 00000 ( 6.5%)" "Laniel (2485905) NO 00909 ( 6.7%)" "Contrecoeur (2459035) V 00000 ( 4.9%)"
However, in order for me to join this table with my boundary layer, I need the records in this field to only contain the 7 digit number in the parenthesis, i.e.
1001559, for the
Witless Bay record.
I cannot figure out how to do this through field calculator using regex. I have looked at ESRI's examples, and they only show examples for substitutions. Using
RIGHT() doesn't work either, as the string lengths are variable.
I have tried something to the extent of the following without success with attached error:
Expression Type: Python 3 Expression: GEOGRAPHY = update_name(!GEOGRAPHY!) Code Block: import re def update_name(geo_name): return re.search(r"""\((.*?)\)""", geo_name)
I do not understand why this wouldn't work. The expression is valid
\((.*?)\). It gives me the following error:
The field is not nullable. [GEOGRAPHY] Failed to execute (CalculateField).
I understand that it gives that error because it can't return a NULL value, but should this not be returning the 7 digit number?