<?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 XQL to get characters from Host Name in Cortex XDR Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/xql-to-get-characters-from-host-name/m-p/532962#M3750</link>
    <description>&lt;P&gt;Hello All:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Our host_names are formatted the same across our fleet.&amp;nbsp; I'd like to pull out the 5-8 characters in the hostname.&amp;nbsp; We've tried using trim, ltrim and rtrim, and even with them nested.&amp;nbsp; Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example&amp;nbsp;WX260920162Q2R&lt;/P&gt;
&lt;P&gt;we want to pull out 0920.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2023 15:09:40 GMT</pubDate>
    <dc:creator>Brad.Herbert</dc:creator>
    <dc:date>2023-03-02T15:09:40Z</dc:date>
    <item>
      <title>XQL to get characters from Host Name</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/xql-to-get-characters-from-host-name/m-p/532962#M3750</link>
      <description>&lt;P&gt;Hello All:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Our host_names are formatted the same across our fleet.&amp;nbsp; I'd like to pull out the 5-8 characters in the hostname.&amp;nbsp; We've tried using trim, ltrim and rtrim, and even with them nested.&amp;nbsp; Any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example&amp;nbsp;WX260920162Q2R&lt;/P&gt;
&lt;P&gt;we want to pull out 0920.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 15:09:40 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/xql-to-get-characters-from-host-name/m-p/532962#M3750</guid>
      <dc:creator>Brad.Herbert</dc:creator>
      <dc:date>2023-03-02T15:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: XQL to get characters from Host Name</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/xql-to-get-characters-from-host-name/m-p/533006#M3753</link>
      <description>&lt;P data-unlink="true"&gt;Hi Brad.Herbert,&lt;BR /&gt;&lt;BR /&gt;If I understand correctly you are wanting to extract these 5-8 characters from the hostname to populate a new field? If that is the case, you can use the &lt;A href="https://docs-cortex.paloaltonetworks.com/r/Cortex-XDR/Cortex-XDR-XQL-Language-Reference/arrayindex" target="_self"&gt;&lt;EM&gt;arrayindex&lt;/EM&gt;&lt;/A&gt; and &lt;A href="https://docs-cortex.paloaltonetworks.com/r/Cortex-XDR/Cortex-XDR-XQL-Language-Reference/arrayindex" target="_self"&gt;&lt;EM&gt;regextract&lt;/EM&gt;&lt;/A&gt; functions&amp;nbsp;together to accomplish this. The regextract function takes a string (in this case the endpoint_name field) followed by a regex to match on the characters you are wanting to extract. In my example below, "WX(\w{5,8})" is the regex, where the function will look for WX followed by 5-8 word characters (letters or numbers), and will &lt;U&gt;only capture the pattern that is contained in the parenthesis&lt;/U&gt; (the 5-8 word characters that follow "WX"). You could also specify a non-capturing pattern that has to match at the end of the regex as well by including it outside of the closing parenthesis and inside the closing double quotation, such as&amp;nbsp;"WX(\w{5,8})YZ" if you want to capture the 5-8 word characters ONLY when they are preceded by "WX" and followed by "YZ".&amp;nbsp;&lt;BR /&gt;The &lt;EM&gt;regextract&lt;/EM&gt; function will return an array of all of the patterns that it matched on, and in this case it may be fine to use this function on its own since it is unlikely to have multiple pattern matches from a single endpoint name, but this function is commonly used in combination with the &lt;EM&gt;arrayindex&lt;/EM&gt; function, which accepts an array (in this case it is the output from our &lt;EM&gt;regextract&lt;/EM&gt; function) and a specified array position, and returns the corresponding value. Arrays are 0-based, meaning when we specify an array position of 0, we are telling the function to return the first value in the array.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;| alter new_field = arrayindex(regextract(endpoint_name, "WX(\w{5,8})"), 0)&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;Regards,&lt;BR /&gt;Ben&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 20:02:52 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/xql-to-get-characters-from-host-name/m-p/533006#M3753</guid>
      <dc:creator>bbucao</dc:creator>
      <dc:date>2023-03-02T20:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: XQL to get characters from Host Name</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/xql-to-get-characters-from-host-name/m-p/533021#M3754</link>
      <description>&lt;P&gt;Thanks Ben, we ended up going this route shortly after I posed the question.&amp;nbsp; Thanks for the response!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 21:27:52 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xdr-discussions/xql-to-get-characters-from-host-name/m-p/533021#M3754</guid>
      <dc:creator>Brad.Herbert</dc:creator>
      <dc:date>2023-03-02T21:27:52Z</dc:date>
    </item>
  </channel>
</rss>

