<?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: How to extract 2 fields in same &amp;quot;rex&amp;quot;? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631269#M219267</link>
    <description>&lt;P&gt;This will get the &lt;STRONG&gt;_first_&lt;/STRONG&gt; statuscode (200)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "(?s)\"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;2\d{2}|4\d{2}|5\d{2})\"?.*\"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\".*"&lt;/LI-CODE&gt;&lt;P&gt;The (?s) allows .* to span multiple lines (. = LF matching).&lt;/P&gt;&lt;P&gt;This will get the&amp;nbsp;&lt;STRONG&gt;_last_&amp;nbsp;&lt;/STRONG&gt;status code&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex max_match=0 "(?s).*\"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;[245]\d{2})\"?.*\"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\""&lt;/LI-CODE&gt;&lt;P&gt;i.e. by starting the regex with a greedy .* before the statusCode it will consume everything up to the last occurrence of statusCode, that exists BEFORE the traceId&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2023 03:34:26 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2023-02-17T03:34:26Z</dc:date>
    <item>
      <title>How to extract 2 fields in same "rex"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631251#M219260</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a search where I am attempting to extracting 2 different fields from one string response using "rex":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;1st Field: rex \"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\"

2nd Field: rex "\"statusCode\"\s:\s\"?(?&amp;amp;lt;tstatusCode&amp;amp;gt;2\d{2}|4\d{2}|5\d{2})\"?"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am attempting to "dedup" the 1st field (traceId) before I pipe those results into the 2nd field (statusCode).&amp;nbsp; I have attempted multiple variation based on Splunk threads and other internet resources.&amp;nbsp; Below is the query I am making:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=myCoolIndex cluster_name="myCoolCluster" sourcetype=myCoolSourceType label_app=myCoolApp ("\"statusCode\"") | rex \"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\" | dedup traceId | rex "\"statusCode\"\s:\s\"?(?&amp;amp;lt;tstatusCode&amp;amp;gt;2\d{2}|4\d{2}|5\d{2})\"?"

//I have tried a lot of other permutations this is just one&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is the response from the log (looks like JSON but it is string type):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;\\Sample Log (Looks like JSON object, but its a string):
"{
  "correlationId" : "",
  "message" : "",
  "tracePoint" : "",
  "priority" : "",
  "category" : "",
  "elapsed" : 0,
  "locationInfo" : {
    "lineInFile" : "",
    "component" : "",
    "fileName" : "",
    "rootContainer" : ""
  },
  "timestamp" : "",
  "content" : {
    "message" : "",
    "originalError" : {
      "statusCode" : "200",
      "errorPayload" : {
        "error" : ""
      }
    },
    "standardizedError" : {
      "statusCode" : "500",
      "errorPayload" : {
        "errors" : [ {
          "error" : {
            "traceId" : "9539510-d8771da0-a7ce-11ed-921c-d6a73926c0ac",
            "errorCode" : "",
            "errorDescription" : ""
            "errorDetails" : ""
          }
        } ]
      }
    }
  },
}"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The intent of the query is to:&lt;/P&gt;
&lt;P&gt;Extract field "traceId", then "dedup" "traceId" (to remove duplicates), then extract field "statusCode" and sort "statusCode" values.&lt;/P&gt;
&lt;P&gt;When running these regEx's independently of eachother they work as expected, but I need to combine them into one query as I will be creating charts on my next step.....&amp;nbsp; All help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 21:02:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631251#M219260</guid>
      <dc:creator>dickersons</dc:creator>
      <dc:date>2023-02-16T21:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract 2 fields in same "rex"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631256#M219261</link>
      <description>&lt;LI-CODE lang="markup"&gt;| rex "\"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;2\d{2}|4\d{2}|5\d{2})\".*?\"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\"" | dedup traceId&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 21:41:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631256#M219261</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-16T21:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract 2 fields in same "rex"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631257#M219262</link>
      <description>&lt;P&gt;This does not produce a match in Splunk or regex101.......&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 21:49:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631257#M219262</guid>
      <dc:creator>dickersons</dc:creator>
      <dc:date>2023-02-16T21:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract 2 fields in same "rex"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631269#M219267</link>
      <description>&lt;P&gt;This will get the &lt;STRONG&gt;_first_&lt;/STRONG&gt; statuscode (200)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "(?s)\"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;2\d{2}|4\d{2}|5\d{2})\"?.*\"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\".*"&lt;/LI-CODE&gt;&lt;P&gt;The (?s) allows .* to span multiple lines (. = LF matching).&lt;/P&gt;&lt;P&gt;This will get the&amp;nbsp;&lt;STRONG&gt;_last_&amp;nbsp;&lt;/STRONG&gt;status code&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex max_match=0 "(?s).*\"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;[245]\d{2})\"?.*\"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\""&lt;/LI-CODE&gt;&lt;P&gt;i.e. by starting the regex with a greedy .* before the statusCode it will consume everything up to the last occurrence of statusCode, that exists BEFORE the traceId&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 03:34:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631269#M219267</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-17T03:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract 2 fields in same "rex"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631283#M219268</link>
      <description>&lt;LI-CODE lang="markup"&gt;| rex "(?ms)\"statusCode\"\s:\s\"?(?&amp;lt;statusCode&amp;gt;2\d{2}|4\d{2}|5\d{2})\".*?\"traceId\"\s:\s\"?(?&amp;lt;traceId&amp;gt;.*?)\"" | dedup traceId&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 17 Feb 2023 06:26:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631283#M219268</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-02-17T06:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract 2 fields in same "rex"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631414#M219303</link>
      <description>&lt;P&gt;Works as stated above.&amp;nbsp; Thanks much for the assistance!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 20:52:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-2-fields-in-same-quot-rex-quot/m-p/631414#M219303</guid>
      <dc:creator>dickersons</dc:creator>
      <dc:date>2023-02-17T20:52:40Z</dc:date>
    </item>
  </channel>
</rss>

