Extracting numbers from string using python in ArcGIS Pro

935
2
Jump to solution
05-31-2019 07:32 AM
Highlighted
New Contributor II

I have a string field in the attribute table for a featureclass which has values like: "abc123_def23_987" and "fks243_ufs876_21". I've created another integer field and wish to extract the numbers after the last underscore (_) so that it yields the numbers "987" and "21" from the examples above respectively. As I'm using I'm using ArcGIS Pro. How can I accomplish this using the python in the "Calculate field" within ArcGIS Pro? I would greatly appreciate help on this. Thanks. 

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Esteemed Contributor
>>> s = "abc123_def23_987"
>>> int(s.split("_")[-1])
987
>>>

View solution in original post

2 Replies
Highlighted
MVP Esteemed Contributor
>>> s = "abc123_def23_987"
>>> int(s.split("_")[-1])
987
>>>

View solution in original post

Highlighted
New Contributor II

Thank you so much for your help. It worked perfectly. I definitely need to Python. Thanks. 

Reply
0 Kudos