<?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: Head scratcher regex in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328306#M97728</link>
    <description>&lt;P&gt;Wow, I feel like a babe in the woods!  Thanks guys!!!&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jan 2018 17:31:16 GMT</pubDate>
    <dc:creator>dbcase</dc:creator>
    <dc:date>2018-01-26T17:31:16Z</dc:date>
    <item>
      <title>Head scratcher regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328302#M97724</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;I have the below data and need to extract three things, 2 of which are pretty easy (method (GET or POST) and responseStatus (numeric value), those I can do).  The one that I'm having trouble with is extracting the last segment of the URL.  For example in the first line I'd like to extract &lt;STRONG&gt;obtainToken&lt;/STRONG&gt;.  On the second line &lt;STRONG&gt;address&lt;/STRONG&gt;.  The third line &lt;STRONG&gt;roost&lt;/STRONG&gt; and the fourth line &lt;STRONG&gt;getAllLightingStatus&lt;/STRONG&gt;.  I've tried several variations to partial success but not all success.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"method":"POST","url":"/rest/blah/sites/1004057/obtainToken?tokenType=WS_CVR","params":{},"requestStartTime":1516982978230,"responseStatus":200,"responseStatusText":"OK","success":true,"responseTime":1516982979338} 

{"method":"GET","url":"/rest/blah/sites/1004057/address","params":{},"requestStartTime":1516982978142,"responseStatus":200,"responseStatusText":"OK","success":true,"responseTime":1516982978901}   

{"method":"POST","url":"/rest/blah/sites/1004057/cloudIntegrations/roost","params":{"method":"POST","path":"/iCtrlGetDeviceStatus"},"requestStartTime":1516982978032,"responseStatus":200,"responseStatusText":"OK","success":true,"responseTime":1516982979118}    

{"method":"GET","url":"/rest/blah/sites/1004057/network/lights/getAllLightingStatus","params":{},"requestStartTime":1516982978146,"responseStatus":500,"responseStatusText":"Internal Server Error","success":false,"responseTime":1516982978914,"data":"Device not connected to server"}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jan 2018 16:24:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328302#M97724</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-26T16:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Head scratcher regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328303#M97725</link>
      <description>&lt;P&gt;How about this for getting the &lt;CODE&gt;final_segment&lt;/CODE&gt; of the url:&lt;BR /&gt;
&lt;CODE&gt;"url":"[^"]+\/(?&amp;lt;final_segment&amp;gt;\w+)(\?[^\/"]+)?"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 16:42:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328303#M97725</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-26T16:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: Head scratcher regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328304#M97726</link>
      <description>&lt;P&gt;Just to account for potentially other characters besides &lt;CODE&gt;\w&lt;/CODE&gt; in the field and potentially a blank field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"url":"[^"]+\/(?&amp;lt;final_segment&amp;gt;[^"?]*)(\?[^\/"]+)?"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's also about 20% more efficient.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 16:54:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328304#M97726</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2018-01-26T16:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Head scratcher regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328305#M97727</link>
      <description>&lt;P&gt;Thanks, guru! I appreciate the correction.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 16:57:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328305#M97727</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-26T16:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Head scratcher regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328306#M97728</link>
      <description>&lt;P&gt;Wow, I feel like a babe in the woods!  Thanks guys!!!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 17:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328306#M97728</guid>
      <dc:creator>dbcase</dc:creator>
      <dc:date>2018-01-26T17:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Head scratcher regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328307#M97729</link>
      <description>&lt;P&gt;Quick question, any reason you're writing regex for the other objects in that data? It looks like a json object.&lt;/P&gt;

&lt;P&gt;With the correct sourcetype the url field should exist already, then you could use a transform like the below (Hoping for feedback on performance from &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/120445"&gt;@cpetterborg&lt;/a&gt; on the below being the master of regex &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;[extract_page_from_url]&lt;BR /&gt;
SOURCE_KEY = url&lt;BR /&gt;
REGEX = \S+\/([^\/\?]+)&lt;BR /&gt;
FORMAT = page::$1&lt;/P&gt;

&lt;P&gt;Also, check out the URL toolbox app (&lt;A href="https://splunkbase.splunk.com/app/2734/" target="_blank"&gt;https://splunkbase.splunk.com/app/2734/&lt;/A&gt;), very handy when working with URL's&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:51:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Head-scratcher-regex/m-p/328307#M97729</guid>
      <dc:creator>mbenwell</dc:creator>
      <dc:date>2020-09-29T17:51:39Z</dc:date>
    </item>
  </channel>
</rss>

