<?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 Regex to split field, optional second field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-split-field-optional-second-field/m-p/273740#M82572</link>
    <description>&lt;P&gt;I have a field that has a pattern where there is a first portion of the string that I'd like to capture into one field, then an optional second field that follows a ':'&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;field1&lt;BR /&gt;
field1:field2&lt;BR /&gt;
field1&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;I've tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;myfield1&amp;gt;.*):(?&amp;lt;myfield2&amp;gt;.*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but that only matches if the original field has the "field1:field2".&lt;BR /&gt;
How should I set up the regex so that it always captures the 'field1' into 'myfield1' and will also capture 'field2' into 'myfield2' if it exists after a ':'?&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2017 05:51:51 GMT</pubDate>
    <dc:creator>pgreer_splunk</dc:creator>
    <dc:date>2017-02-02T05:51:51Z</dc:date>
    <item>
      <title>Regex to split field, optional second field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-split-field-optional-second-field/m-p/273740#M82572</link>
      <description>&lt;P&gt;I have a field that has a pattern where there is a first portion of the string that I'd like to capture into one field, then an optional second field that follows a ':'&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;field1&lt;BR /&gt;
field1:field2&lt;BR /&gt;
field1&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;I've tried&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;myfield1&amp;gt;.*):(?&amp;lt;myfield2&amp;gt;.*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but that only matches if the original field has the "field1:field2".&lt;BR /&gt;
How should I set up the regex so that it always captures the 'field1' into 'myfield1' and will also capture 'field2' into 'myfield2' if it exists after a ':'?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 05:51:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-split-field-optional-second-field/m-p/273740#M82572</guid>
      <dc:creator>pgreer_splunk</dc:creator>
      <dc:date>2017-02-02T05:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to split field, optional second field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-split-field-optional-second-field/m-p/273741#M82573</link>
      <description>&lt;P&gt;Try this regex and see if it works out for your case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| rex "(?&amp;lt;myField1&amp;gt;[^\s:]+):*(?&amp;lt;myField2&amp;gt;\S*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/c72f4m/2"&gt;See Extraction Here&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 06:06:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-split-field-optional-second-field/m-p/273741#M82573</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2017-02-02T06:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to split field, optional second field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-split-field-optional-second-field/m-p/273742#M82574</link>
      <description>&lt;P&gt;That seems to have done it.&lt;/P&gt;

&lt;P&gt;So if reading it correctly, the regex says "store into "myField1" one or more characters (in the string) that are NOT whitespace and NOT ':'. Which gobbles up anything until the next match between the groupings, which is zero or more of ':', then store into "myField2" zero or more non-whitespace characters".&lt;/P&gt;

&lt;P&gt;That seems to have done it for me. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 17:25:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-split-field-optional-second-field/m-p/273742#M82574</guid>
      <dc:creator>pgreer_splunk</dc:creator>
      <dc:date>2017-02-02T17:25:16Z</dc:date>
    </item>
  </channel>
</rss>

