<?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: Regex for fields that may or not be filled? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-fields-that-may-or-not-be-filled/m-p/99883#M25794</link>
    <description>&lt;P&gt;You may want to try using an eval statement such as;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval sourcecomputer=if(sourcecomputer=="", "missing", sourcecomputer)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will rewrite your field that has an empty value (not exactly NULL) and replace it with missing and otherwise replace it with whatever is already in the sourcecomputer field.&lt;/P&gt;

&lt;P&gt;That will work for one value at a time, otherwise, you may want to use the sed mode to replace empty values in your raw string.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|rex field=_raw mode=sed "s/:\s,/:\smissing,/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Oct 2012 23:33:06 GMT</pubDate>
    <dc:creator>Rob</dc:creator>
    <dc:date>2012-10-23T23:33:06Z</dc:date>
    <item>
      <title>Regex for fields that may or not be filled?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-fields-that-may-or-not-be-filled/m-p/99882#M25793</link>
      <description>&lt;P&gt;Hey Guys, tricky one I came across.&lt;BR /&gt;
I have to find and match on fields that may not be present.&lt;BR /&gt;
So far I have this to find the fields when they exist:&lt;/P&gt;

&lt;P&gt;"Source computer: (?P&lt;SOURCECOMPUTER&gt;[^,]+) ,Source IP: (?P&lt;SOURCEIP&gt;[^,]+)"&lt;/SOURCEIP&gt;&lt;/SOURCECOMPUTER&gt;&lt;/P&gt;

&lt;P&gt;But it fails when the field is not filled and just looks like this:&lt;BR /&gt;
"Source computer: " or "Source IP: ".&lt;BR /&gt;
In fact the whole thing can look like this:&lt;BR /&gt;
"Source computer: ,Source IP: ,&lt;NEXT field="" etc=""&gt;"&lt;/NEXT&gt;&lt;/P&gt;

&lt;P&gt;How can I overcome this and maybe insert a "null" or "missing" string if the field is empty?&lt;BR /&gt;
Ive tried with no success:&lt;BR /&gt;
| fillnull value="missing" sourcecomputer&lt;BR /&gt;
| fillnull value=NULL sourcecomputer&lt;/P&gt;

&lt;P&gt;Anyone? Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2012 22:47:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-fields-that-may-or-not-be-filled/m-p/99882#M25793</guid>
      <dc:creator>mrgibbon</dc:creator>
      <dc:date>2012-10-23T22:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for fields that may or not be filled?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-fields-that-may-or-not-be-filled/m-p/99883#M25794</link>
      <description>&lt;P&gt;You may want to try using an eval statement such as;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval sourcecomputer=if(sourcecomputer=="", "missing", sourcecomputer)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will rewrite your field that has an empty value (not exactly NULL) and replace it with missing and otherwise replace it with whatever is already in the sourcecomputer field.&lt;/P&gt;

&lt;P&gt;That will work for one value at a time, otherwise, you may want to use the sed mode to replace empty values in your raw string.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|rex field=_raw mode=sed "s/:\s,/:\smissing,/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2012 23:33:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-fields-that-may-or-not-be-filled/m-p/99883#M25794</guid>
      <dc:creator>Rob</dc:creator>
      <dc:date>2012-10-23T23:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Regex for fields that may or not be filled?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-for-fields-that-may-or-not-be-filled/m-p/99884#M25795</link>
      <description>&lt;P&gt;Answered my own question, using * and not + at the end of the search.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2012 00:42:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-for-fields-that-may-or-not-be-filled/m-p/99884#M25795</guid>
      <dc:creator>mrgibbon</dc:creator>
      <dc:date>2012-10-24T00:42:23Z</dc:date>
    </item>
  </channel>
</rss>

