<?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 write the regex to parse comma separated values for a single field in a log? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116789#M31021</link>
    <description>&lt;P&gt;Yes. When I get everything inside the parenthesis, it looks like how you describe above. &lt;/P&gt;</description>
    <pubDate>Fri, 27 Mar 2015 20:04:23 GMT</pubDate>
    <dc:creator>sswansonchtr</dc:creator>
    <dc:date>2015-03-27T20:04:23Z</dc:date>
    <item>
      <title>How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116785#M31017</link>
      <description>&lt;P&gt;I need some help trying to parse a log that may have something like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; 192.168.x.x process: field_a (value_1, value_2,...)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Where &lt;CODE&gt;value_1&lt;/CODE&gt; and &lt;CODE&gt;value_2&lt;/CODE&gt; (and so on) are all values for &lt;CODE&gt;field_a&lt;/CODE&gt;. You can have either 1 value to up to about 6 values for &lt;CODE&gt;field_a&lt;/CODE&gt; in a single log. An example would be:  &lt;/P&gt;

&lt;P&gt;session_state (SYN, ACK)&lt;BR /&gt;
or&lt;BR /&gt;
session_state (SYN)&lt;/P&gt;

&lt;P&gt;Any help would be nice. Right now I am limited to reporting everything between the parenthesis as the value for &lt;CODE&gt;field_a&lt;/CODE&gt;. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:20:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116785#M31017</guid>
      <dc:creator>sswansonchtr</dc:creator>
      <dc:date>2020-09-28T19:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116786#M31018</link>
      <description>&lt;P&gt;Assuming that the values are alpha-numeric only, you have at least one value and a max of six, the parens are only found around the values list in the event, and you are wanting to do this at search time with a &lt;CODE&gt;rex&lt;/CODE&gt; command, this should work for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your search&amp;gt; | rex field=_raw "\((?P&amp;lt;value_1&amp;gt;\w+)(,\s+(?P&amp;lt;value_2&amp;gt;\w+)?(,\s+(?P&amp;lt;value_3&amp;gt;\w+)?(,\s+(?P&amp;lt;value_4&amp;gt;\w+)?(,\s+(?P&amp;lt;value_5&amp;gt;\w+)?(,\s+(?P&amp;lt;value_6&amp;gt;\w+)?\)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Mar 2015 21:58:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116786#M31018</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2015-03-26T21:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116787#M31019</link>
      <description>&lt;P&gt;A couple key notes: &lt;BR /&gt;
 - I am adding this regex as an extraction in props.conf for a TA. &lt;BR /&gt;
 - There can be multiple words for a single value. (ie. signature ( Block List, Threat List, Traffic Misuse))&lt;BR /&gt;
 - The values are all words, no numbers. &lt;/P&gt;

&lt;P&gt;I tried something similar to the above in a props extraction but it creates a field extraction for each 'value_x' so i would end up with a bunch of fields. I guess I can always rename them in search or alias them all to the same field. The real challenge seems to be only parsing the number of values available. If there is a single value, the search above, as well as my other tries, continue to parse the next bits of info as the next value_2. Trying to get it to stop at the ')' or if a comma, continue with value_2, then repeat until the ')' comes. The actual log continues past this 'field_a'. I figure if I can get the extractions working on the one, I can replicate to the other fields etc. Here is an example of what I am talking about.&lt;/P&gt;

&lt;P&gt;ex log: time_stamp 192.168.x.x process: field_a (value_1, value_2,...) , field_b (value_1, value_2,...), field_c (value) &lt;/P&gt;

&lt;P&gt;Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116787#M31019</guid>
      <dc:creator>sswansonchtr</dc:creator>
      <dc:date>2020-09-28T19:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116788#M31020</link>
      <description>&lt;P&gt;You said you're able to show everything with brackets as value of field_a. So how does you fields look &lt;BR /&gt;
Sample log&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;time_stamp 192.168.x.x process: field_a (value_1, value_2) , field_b (value_3, value_4,value_5), field_c (value_5) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is it something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time              field_a                 field_b             field_c
time_stamp    "value_1,value_2"    "value_3,value_4,value_5"      "value_6"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Mar 2015 19:54:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116788#M31020</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-03-27T19:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116789#M31021</link>
      <description>&lt;P&gt;Yes. When I get everything inside the parenthesis, it looks like how you describe above. &lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2015 20:04:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116789#M31021</guid>
      <dc:creator>sswansonchtr</dc:creator>
      <dc:date>2015-03-27T20:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116790#M31022</link>
      <description>&lt;P&gt;I got 2 options:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;props.conf&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [my_sourcetype]
 # &lt;A href="https://regex101.com/r/bQ1kK6/1" target="test_blank"&gt;https://regex101.com/r/bQ1kK6/1&lt;/A&gt;
 EXTRACT-0 = session_state \(([^\)]+)\)
 EVAL-session_state = split(session_state,",")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;props.conf&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [my_sourcetype]
 # &lt;A href="https://regex101.com/r/bQ1kK6/1" target="test_blank"&gt;https://regex101.com/r/bQ1kK6/1&lt;/A&gt;
 EXTRACT-0 = session_state \(([^\)]+)\)
 REPORT-0 = session_state_mv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;transforms.conf&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [session_state_mv]
 SOURCE_KEY = session_state
 REGEX = ([A-Z]+)
 MV_ADD = true
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2015 23:10:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116790#M31022</guid>
      <dc:creator>skawasaki_splun</dc:creator>
      <dc:date>2015-05-07T23:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116791#M31023</link>
      <description>&lt;P&gt;To go off what Satoshi was showing you, but putting it into all rex in the search, here is what goes on.  First you extract the SESSION_STATE using the rex command, then you take put SESSION_STATE through eval with the splunk command delimited by a command then you have a multi-valued field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal | head 1 | eval RAW="192.168.x.x process: field_a (value_1, value_2,value_3,value_4,value_5,value_6)" | rex field=RAW "\((?&amp;lt;SESSION_STATE&amp;gt;[^)]+)" | eval SESSION_VALUES=split(SESSION_STATE,",") | table RAW,SESSION_STATE,SESSION_VALUES
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/35857-screen+shot+2015-05-08+at+6.47.03+am.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:51:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116791#M31023</guid>
      <dc:creator>dmaislin_splunk</dc:creator>
      <dc:date>2020-09-28T19:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to write the regex to parse comma separated values for a single field in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116792#M31024</link>
      <description>&lt;P&gt;Thanks. I used option 1 and this worked. Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2015 16:36:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-the-regex-to-parse-comma-separated-values-for-a/m-p/116792#M31024</guid>
      <dc:creator>sswansonchtr</dc:creator>
      <dc:date>2015-05-08T16:36:32Z</dc:date>
    </item>
  </channel>
</rss>

