<?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 Using Wildcard to extract values with Field Calculator? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-wildcard-to-extract-values-with-field/m-p/632550#M49284</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to extract a portion of an existing field in an attribute table to a new field using Field Calculator and have been running into some difficulties. It seems like there must be a way to do this, although with my limited VBS and Python experience I can't be certain. I'm working with 10.0 (sp. 2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The exact problem is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The layer I'm working with has a very long field, [PopUp] (which was created when converting a KMZ file to a feature class) whose contents for each feature look something like this: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;...&amp;lt;td&amp;gt;LAND USE CODE&amp;lt;/td&amp;gt; &amp;lt;td&amp;gt;954&amp;lt;/td&amp;gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to extract just the Land Use Code from the [PopUp] field and populate a new field with it (either a numeric field or string, I don't care).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Land Use Code changes based on the feature in question and the length of the string varies for each feature both before and after this segment which I want to extract (so I can't use a function which just grabs X number of characters from the left or right side).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is this possible using the Field Calculator, with either Python or VBScript?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If so, I assume it would require some way to indicate a wildcard on either side of the Land Use Code, but I know it doesn't work the same as a simple SQL query/search.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Feb 2013 17:51:03 GMT</pubDate>
    <dc:creator>DanEckberg</dc:creator>
    <dc:date>2013-02-07T17:51:03Z</dc:date>
    <item>
      <title>Using Wildcard to extract values with Field Calculator?</title>
      <link>https://community.esri.com/t5/python-questions/using-wildcard-to-extract-values-with-field/m-p/632550#M49284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to extract a portion of an existing field in an attribute table to a new field using Field Calculator and have been running into some difficulties. It seems like there must be a way to do this, although with my limited VBS and Python experience I can't be certain. I'm working with 10.0 (sp. 2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The exact problem is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The layer I'm working with has a very long field, [PopUp] (which was created when converting a KMZ file to a feature class) whose contents for each feature look something like this: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;...&amp;lt;td&amp;gt;LAND USE CODE&amp;lt;/td&amp;gt; &amp;lt;td&amp;gt;954&amp;lt;/td&amp;gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to extract just the Land Use Code from the [PopUp] field and populate a new field with it (either a numeric field or string, I don't care).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Land Use Code changes based on the feature in question and the length of the string varies for each feature both before and after this segment which I want to extract (so I can't use a function which just grabs X number of characters from the left or right side).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is this possible using the Field Calculator, with either Python or VBScript?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If so, I assume it would require some way to indicate a wildcard on either side of the Land Use Code, but I know it doesn't work the same as a simple SQL query/search.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 17:51:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-wildcard-to-extract-values-with-field/m-p/632550#M49284</guid>
      <dc:creator>DanEckberg</dc:creator>
      <dc:date>2013-02-07T17:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Wildcard to extract values with Field Calculator?</title>
      <link>https://community.esri.com/t5/python-questions/using-wildcard-to-extract-values-with-field/m-p/632551#M49285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you familiar with cursors?&amp;nbsp; This can be done very easily with an update cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fc = r'path\to\your\featureClass'
rows = arcpy.UpdateCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Land_Use = int(''.join([i for i in row.PopUp if i.isdigit()]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Where 'Land_Use' is the new field you want to extract the values to (I had it set up as a short integer field, hence the int() value).&amp;nbsp; The fc variable is just the path pointing to your feature class.&amp;nbsp; This just runs a simple test to extract all values within the text string that are integers.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:54:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-wildcard-to-extract-values-with-field/m-p/632551#M49285</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T02:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using Wildcard to extract values with Field Calculator?</title>
      <link>https://community.esri.com/t5/python-questions/using-wildcard-to-extract-values-with-field/m-p/632552#M49286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, that worked and helped lead me to my ultimate solution, which was as follows (and conducted from the stand-alone Python Window, not Field Calculator):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import re
fc='file path'
rows=arcpy.UpdateCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.FieldName = re.search('LAND USE CODE&amp;lt;/td&amp;gt;\n&amp;lt;td&amp;gt;(\d*)&amp;lt;' , row.PopUp).group(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:54:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-wildcard-to-extract-values-with-field/m-p/632552#M49286</guid>
      <dc:creator>DanEckberg</dc:creator>
      <dc:date>2021-12-12T02:54:47Z</dc:date>
    </item>
  </channel>
</rss>

