<?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 use regex in calculated fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629672#M218758</link>
    <description>&lt;P&gt;Thanks, thats works.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Feb 2023 06:32:48 GMT</pubDate>
    <dc:creator>bitnapper</dc:creator>
    <dc:date>2023-02-06T06:32:48Z</dc:date>
    <item>
      <title>How to use regex in calculated fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629478#M218672</link>
      <description>&lt;P class="lia-align-justify"&gt;Hi, I've been told, that using field extractions on json is not best practis and that I should use calculated fields instead. In some cases thats easy and I can use replace or other methods to do that but in some it is more difficult.&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;I have some events giving me information about software versions. When I try to extract the version string from as follows, I get the results for events containing this string. In all other cases I get the complete string instead. What I need is the matching string or nothing. I couldn't figure out how to do that.&lt;/P&gt;
&lt;PRE&gt;replace(message, "^My Software Version (\S+).*", "\1") &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 16:04:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629478#M218672</guid>
      <dc:creator>bitnapper</dc:creator>
      <dc:date>2023-02-03T16:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Regex in calculated fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629481#M218673</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/245847"&gt;@bitnapper&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I'd use the rex command in sed mode to do this (&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.0.3/SearchReference/Rex" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.0.3/SearchReference/Rex&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=message mode=sed "s/^My Software Version (\S+).*/NA/g"&lt;/LI-CODE&gt;&lt;P&gt;I'm not sure about the condition, could you share some sample of both data types with the exact substitution you whould have?&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 11:41:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629481#M218673</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-02-03T11:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Regex in calculated fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629498#M218681</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;thanks for your reply. I tested the regex with the | rex command. It not that I can't extract the data. I just can't extract it with the calculated field extraction. As far as I understand, everything that works with | eval would work in calculated fields. Thats why I do it with replace in cases where I know that I have a match in every event.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 13:21:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629498#M218681</guid>
      <dc:creator>bitnapper</dc:creator>
      <dc:date>2023-02-03T13:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use regex in calculated fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629656#M218750</link>
      <description>&lt;P&gt;Using replace will replace the string if a match is found. If no match is found, it will not replace aything.&lt;/P&gt;&lt;P&gt;You can using "if" statement&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if(match(message, "^My Software Version (\S+).*"), replace(message, "^My Software Version (\S+).*", "\1"), "")&lt;/LI-CODE&gt;&lt;P&gt;The last "" means that the assigned field will be an empty string, but if you want that field not to exist for that event, then use &lt;STRONG&gt;null()&lt;/STRONG&gt; instead&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2023 22:40:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629656#M218750</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-05T22:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use regex in calculated fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629672#M218758</link>
      <description>&lt;P&gt;Thanks, thats works.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2023 06:32:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-regex-in-calculated-fields/m-p/629672#M218758</guid>
      <dc:creator>bitnapper</dc:creator>
      <dc:date>2023-02-06T06:32:48Z</dc:date>
    </item>
  </channel>
</rss>

