<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Extracting numbers from string using python in ArcGIS Pro in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/391647#M17261</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; s &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"abc123_def23_987"&lt;/SPAN&gt;
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;s&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"_"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="number token"&gt;987&lt;/SPAN&gt;
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:57:09 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-12-11T17:57:09Z</dc:date>
    <item>
      <title>Extracting numbers from string using python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/391646#M17260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a string field in the attribute table for a featureclass which has values like: "&lt;STRONG&gt;abc123_def23_987&lt;/STRONG&gt;" and "&lt;STRONG&gt;fks243_ufs876_21&lt;/STRONG&gt;". I've created another integer field and wish to extract the numbers after the last underscore (&lt;STRONG&gt;_&lt;/STRONG&gt;) so that it yields the numbers "&lt;STRONG&gt;987&lt;/STRONG&gt;" and "&lt;STRONG&gt;21&lt;/STRONG&gt;" from the examples above respectively. As I'm using&amp;nbsp;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.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2019 14:32:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/391646#M17260</guid>
      <dc:creator>KhaledAli1</dc:creator>
      <dc:date>2019-05-31T14:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from string using python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/391647#M17261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; s &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"abc123_def23_987"&lt;/SPAN&gt;
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;s&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"_"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="number token"&gt;987&lt;/SPAN&gt;
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:57:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/391647#M17261</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T17:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from string using python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/391648#M17262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for your help. It worked perfectly. I definitely need to Python. Thanks.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2019 18:19:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/391648#M17262</guid>
      <dc:creator>KhaledAli1</dc:creator>
      <dc:date>2019-05-31T18:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from string using python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023091#M36848</link>
      <description>&lt;P&gt;In the Calculate Field tool, you can use Regular Expressions.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Parser:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Python&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Code Block:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;import re&lt;BR /&gt;def only_num(numbers):&lt;BR /&gt;return re.findall('\d+',numbers)[-1]&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Expression:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;only_num(!your_field!)&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 18:03:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023091#M36848</guid>
      <dc:creator>GFEP</dc:creator>
      <dc:date>2021-02-03T18:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from string using python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023151#M36855</link>
      <description>&lt;P&gt;I like regular expressions, a lot, but I also realize they aren't ideal for simple situations like the OP presented here.&amp;nbsp; Since using split involves using built-in functionality, i.e., no need to import additional modules, and split is likely 3-4 times faster than regular expression in this case; I think using split is a better approach.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 19:37:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023151#M36855</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-02-03T19:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from string using python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023159#M36857</link>
      <description>&lt;P&gt;Hello Joshua.&lt;/P&gt;&lt;P&gt;But if you try to extract only numbers&amp;nbsp; in a string that hasn't any "splitting character", your suggestion doesn't work. So, regular expressions can be a very powerfull option. I ran this code today in a geodatabase with 10,000 polygons. It took 1 second to calculate.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 19:45:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023159#M36857</guid>
      <dc:creator>GFEP</dc:creator>
      <dc:date>2021-02-03T19:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting numbers from string using python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023165#M36860</link>
      <description>&lt;P&gt;There has to be some kind of splitting character or characters, otherwise there would be no way to know what differentiates one group of numbers in a string from another.&amp;nbsp; In the OP's original example and data set, the strings happened to be very structured with a convenient splitting character right before the final group of numbers, which made using str.split simple.&amp;nbsp; In your example, relying on the decimal digit regex special sequence implies the splitting character is any non-decimal digit, which presents its own challenges if the numbers included commas or periods.&lt;/P&gt;&lt;P&gt;As I mentioned above, I like and use regex all the time, but it can also be overkill when the situation can be handled with basic string methods.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 20:08:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/extracting-numbers-from-string-using-python-in/m-p/1023165#M36860</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-02-03T20:08:31Z</dc:date>
    </item>
  </channel>
</rss>

