<?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: Extract substring from Splunk String using regex in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584953#M203779</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243044"&gt;@user9025&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;if you haven't the field hostname, search the regex on the _raw&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "^\w+\.\w+\.(?&amp;lt;my_host&amp;gt;\w{4})"&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
    <pubDate>Mon, 14 Feb 2022 11:02:14 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2022-02-14T11:02:14Z</dc:date>
    <item>
      <title>How to Extract substring from Splunk String using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584946#M203774</link>
      <description>&lt;DIV class=""&gt;
&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class=""&gt;
&lt;DIV class=""&gt;
&lt;P&gt;I ave a field "hostname" in splunk logs which is available in my event as "host = server.region.ab1dc2.mydomain.com".&lt;/P&gt;
&lt;P&gt;I can refer to host with same name "host" in splunk query. I want to extract the substring with 4 digits after two dots ,for the above example , it will be "ab1d". How my splunk query should look like for this extraction?&lt;/P&gt;
&lt;P&gt;Basically I have been given a string, and want to skip two dots and then take the four characters after that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 14 Feb 2022 16:13:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584946#M203774</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-02-14T16:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring from Splunk String using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584948#M203775</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243044"&gt;@user9025&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;please try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=hostname "^\w+\.\w+\.(?&amp;lt;my_host&amp;gt;\w{4})"&lt;/LI-CODE&gt;&lt;P&gt;that you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/fWR8LV/1" target="_blank"&gt;https://regex101.com/r/fWR8LV/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 10:21:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584948#M203775</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-02-14T10:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring from Splunk String using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584950#M203776</link>
      <description>&lt;P&gt;Thanks for reply but hostname is not available as a raw text.Its a filed, that can be referred by"host" directly,If i click on event, I see one field name as "host".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in my splunk query, I can directly refer "host" without rex field.Following is how my event looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;INFO&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class=""&gt;2022-02-14T02:16:15&lt;/SPAN&gt;,&lt;SPAN class=""&gt;129&amp;nbsp;&lt;/SPAN&gt;servername requestid=asds This is my log info&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;UL class=""&gt;&lt;LI&gt;&lt;SPAN class=""&gt;host =Hostname&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;source =logfilename&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN class=""&gt;I am looking something, extract_regex(string,regex) where i can pass extract_regex(host,REGEX),&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;i tried to replace&amp;nbsp;REGEX with yours, but it does not work&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 14 Feb 2022 10:49:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584950#M203776</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-02-14T10:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring from Splunk String using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584953#M203779</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243044"&gt;@user9025&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;if you haven't the field hostname, search the regex on the _raw&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "^\w+\.\w+\.(?&amp;lt;my_host&amp;gt;\w{4})"&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 11:02:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584953#M203779</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-02-14T11:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring from Splunk String using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584958#M203782</link>
      <description>&lt;P&gt;My existing query looks like follow and it works fine:&lt;/P&gt;&lt;P&gt;index=Myindex&amp;nbsp; sourcetype=app-sourcename "text to search" |&amp;nbsp; eval hostname= substr(host, len(host)-17) | stats count by host&lt;/P&gt;&lt;P&gt;Getting last 17 characters from string host.&lt;/P&gt;&lt;P&gt;Now i want to do operation on host before it goes to stats ,which is to extract 4 chars from hostname after skipping 2 dots, can u tell how can I modify existing query to do that?I searched sot string manipulation functions, but it does not seem to work here&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;&amp;nbsp;&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;</description>
      <pubDate>Mon, 14 Feb 2022 11:31:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584958#M203782</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-02-14T11:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring from Splunk String using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584959#M203783</link>
      <description>&lt;P&gt;My existing query looks like follow and it works fine:&lt;/P&gt;&lt;P&gt;index=Myindex&amp;nbsp; sourcetype=app-sourcename "text to search" |&amp;nbsp; eval hostname= substr(host, len(host)-17) | stats count by host&lt;/P&gt;&lt;P&gt;Getting last 17 characters from string host.&lt;/P&gt;&lt;P&gt;Now i want to do operation on host before it goes to stats ,which is to extract 4 chars from hostname after skipping 2 dots, can u tell how can I modify existing query to do that?I searched sot string manipulation functions, but it does not seem to work here&lt;/P&gt;</description>
      <pubDate>Mon, 14 Feb 2022 11:31:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-substring-from-Splunk-String-using-regex/m-p/584959#M203783</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-02-14T11:31:46Z</dc:date>
    </item>
  </channel>
</rss>

