<?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 Regex in Cortex XDR XQL query in General Topics</title>
    <link>https://live.paloaltonetworks.com/t5/general-topics/using-regex-in-cortex-xdr-xql-query/m-p/560519#M113618</link>
    <description>&lt;P&gt;I want to extract a particular string from a particular field value from the Cortex XDR endpoint category and use it in XQL query. Is it possible to do that?&lt;/P&gt;
&lt;P&gt;For example from the below string (it is a field )&lt;/P&gt;
&lt;P&gt;arn:aws:ec2:eu-abcd-1:123456789:instance/i-000000000000&lt;/P&gt;
&lt;P&gt;I would like to extract the number 123456789 in an XQL query and use it to get the count of all the hosts which has the same value as 123456789.&lt;/P&gt;
&lt;P&gt;How can I do that?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-PRODUCT title="Cortex XDR" id="Cortex_XDR"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&amp;nbsp;&lt;LI-PRODUCT title="Endpoint Protection" id="Endpoint_Protection"&gt;&lt;/LI-PRODUCT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Oct 2023 12:41:31 GMT</pubDate>
    <dc:creator>Kavurisowmya</dc:creator>
    <dc:date>2023-10-04T12:41:31Z</dc:date>
    <item>
      <title>Using Regex in Cortex XDR XQL query</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/using-regex-in-cortex-xdr-xql-query/m-p/560519#M113618</link>
      <description>&lt;P&gt;I want to extract a particular string from a particular field value from the Cortex XDR endpoint category and use it in XQL query. Is it possible to do that?&lt;/P&gt;
&lt;P&gt;For example from the below string (it is a field )&lt;/P&gt;
&lt;P&gt;arn:aws:ec2:eu-abcd-1:123456789:instance/i-000000000000&lt;/P&gt;
&lt;P&gt;I would like to extract the number 123456789 in an XQL query and use it to get the count of all the hosts which has the same value as 123456789.&lt;/P&gt;
&lt;P&gt;How can I do that?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-PRODUCT title="Cortex XDR" id="Cortex_XDR"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&amp;nbsp;&lt;LI-PRODUCT title="Endpoint Protection" id="Endpoint_Protection"&gt;&lt;/LI-PRODUCT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 12:41:31 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/using-regex-in-cortex-xdr-xql-query/m-p/560519#M113618</guid>
      <dc:creator>Kavurisowmya</dc:creator>
      <dc:date>2023-10-04T12:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using Regex in Cortex XDR XQL query</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/using-regex-in-cortex-xdr-xql-query/m-p/560548#M113621</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Kavurisowmya,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes,&lt;SPAN&gt;&amp;nbsp;you may. Vendor Logs ingested from some unsupported external data sources sent to Cortex XDR may not match the format of the data already present in XDR from other sources.&amp;nbsp; In this case, you can use additional XQL functions to transform the data within your custom parsing rules. Reference&amp;nbsp;&lt;A href="https://docs-cortex.paloaltonetworks.com/r/Cortex-XDR/Cortex-XDR-Pro-Administrator-Guide/Ingest-External-Alerts" target="_blank" rel="noopener"&gt;Ingest External Alerts • Cortex XDR Pro Administrator Guide • Reader • Palo Alto Networks documentation portal&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;You may use&amp;nbsp;regex to convert the fields to extract the data to facilitate matching with Cortex XDR format. For example, say you need to map the port but your source field contains both the IP address and port (192.168.1.200:8080). To extract everything after the :, use the following regex:&lt;/EM&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;^[^:]*_&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example with Zscaler logs where this&amp;nbsp;&lt;SPAN&gt;statement performs a regular expression match on any group of characters except whitespace characters, the resulting array will then have each field in an index,&amp;nbsp;and we can simply choose the array index that corresponds to the field we want to assign.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;String with a delimiter&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;dataset = zscaler_nsssaasfilelog_raw&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;| fields _raw_log&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;| alter date = arrayindex(regextract(_raw_log, "[^\s]+"),0)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In the example, the 0th array index (recall that arrays are 0-indexed data structures,&amp;nbsp;so the first value is stored at index 0) corresponds to the first value in the log format.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In your example the delimiter is &lt;STRONG&gt;:&lt;/STRONG&gt; so you will need to pull selected value for the regex to pull the data values you would like to extract.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reference&lt;/P&gt;
&lt;UL&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;A href="https://regexr.com/" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;https://regexr.com/&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;A href="https://regex101.com/" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;regex101: build, test, and debug regex&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt; - the regex implementation used by XDR is in Golang. This change affects the regex syntax and supported options. When using regex101, make sure you select the correct "Flavor" on the left.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;A href="https://docs-cortex.paloaltonetworks.com/r/Cortex-XDR/Cortex-XDR-XQL-Language-Reference/regextract" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;regextract • Cortex XDR XQL Language Reference • Reader • Palo Alto Networks documentation portal&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt; - XQL uses RE2 for its regular expression implementation which supports single group capturing, look behind and other regex features are not supported.&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="font-weight: 400;" aria-level="1"&gt;&lt;A href="https://docs.paloaltonetworks.com/cortex/cortex-xdr/cortex-xdr-xql-language-reference/xql-functions-reference" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;XQL Functions Reference&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you found this answer helpful, please like and select Accept as Solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 15:15:58 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/using-regex-in-cortex-xdr-xql-query/m-p/560548#M113621</guid>
      <dc:creator>jtalton</dc:creator>
      <dc:date>2023-10-04T15:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using Regex in Cortex XDR XQL query</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/using-regex-in-cortex-xdr-xql-query/m-p/560557#M113622</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;I love regex, but don't have any experience with XQL, but I think the bit of code you are looking for is:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| alter uid = arrayindex(regextract(_raw_log, "(\S+?:){4}(\d+)"),2)&lt;/LI-CODE&gt;
&lt;P&gt;...assuming &lt;STRONG&gt;regextract&lt;/STRONG&gt; returns an array with three elements: the match and two groups. Hence you want the second group at index '2'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://regex101.com/r/24tFJl/1" target="_blank"&gt;https://regex101.com/r/24tFJl/1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Seb.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 15:53:38 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/using-regex-in-cortex-xdr-xql-query/m-p/560557#M113622</guid>
      <dc:creator>seb_rupik</dc:creator>
      <dc:date>2023-10-04T15:53:38Z</dc:date>
    </item>
  </channel>
</rss>

