<?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 extract fields between pipe in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532768#M4406</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm indexing events in JSON format and I need a way of extracting into individual fields the values broken up by the pipe in the 'Subject' field seen below;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;RecipientAddress&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;bla@bla.com&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;SenderAddress&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t string"&gt;fred@fred.com&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;Size&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t number"&gt;201828&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;Status&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t string"&gt;FilteredAsSpam&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;Subject&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t string"&gt;1|fdbe21c9-xxxxx|195.168.1.1|Comms@fred.com|([Ext]Hi, join us for the 10-year roundup) 12/11/2020 8:21:14 AM&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;ToIP&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t null"&gt;null&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I seem to be struggling to get a regex to work, not sure whether I need to take into account the JSON formatting?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Dec 2020 10:24:22 GMT</pubDate>
    <dc:creator>jacqu3sy</dc:creator>
    <dc:date>2020-12-11T10:24:22Z</dc:date>
    <item>
      <title>Regex to extract fields between pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532768#M4406</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm indexing events in JSON format and I need a way of extracting into individual fields the values broken up by the pipe in the 'Subject' field seen below;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;RecipientAddress&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;bla@bla.com&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;SenderAddress&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t string"&gt;fred@fred.com&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;Size&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t number"&gt;201828&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;Status&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t string"&gt;FilteredAsSpam&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;Subject&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t string"&gt;1|fdbe21c9-xxxxx|195.168.1.1|Comms@fred.com|([Ext]Hi, join us for the 10-year roundup) 12/11/2020 8:21:14 AM&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="key level-1"&gt;&lt;SPAN class="key-name"&gt;ToIP&lt;/SPAN&gt;:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="t null"&gt;null&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I seem to be struggling to get a regex to work, not sure whether I need to take into account the JSON formatting?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 10:24:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532768#M4406</guid>
      <dc:creator>jacqu3sy</dc:creator>
      <dc:date>2020-12-11T10:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields between pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532778#M4408</link>
      <description>&lt;P&gt;I'm guessing that you have copied and pasted that example (with redaction) from the event view in search results? (please use the &amp;lt;/&amp;gt; code formatter as it helps preserve formatting)&lt;BR /&gt;&lt;BR /&gt;If you are applying regex on the _raw field, you will need to account for the json formatting that was in the original event so your regex might need to begin with something like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"Subject\": ....etc..."&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if its well formed json (such that it shows nicely in search results) and you are doing the extraction in a search you can use spath to pull out the fields for you, so then you can apply the regex just to the Subject field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;your search...|spath|table Subject&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from here, assuming the | delimited fields are consistent, a simple rex command should work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;rex field=Subject "(?P&amp;lt;number&amp;gt;[^\|]+)\|(?P&amp;lt;id&amp;gt;[^\|]+)\|(?P&amp;lt;ip&amp;gt;[^\|]+)\|(?P&amp;lt;email&amp;gt;[^\|]+)\|(?P&amp;lt;subject&amp;gt;[^$]+)"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 16:21:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532778#M4408</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2020-12-11T16:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields between pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532817#M4413</link>
      <description>&lt;P&gt;So yeh, from well formed JSON, trying to run the query from a Search, where the Subject field is being extracted as expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your Regex and it didnt seem to like it. The first field should be the 1 after 'Subject :' and before the first pipe, the second field the message ID in between the first and second pipe etc.&lt;/P&gt;&lt;P&gt;Whenever I tried doing it myself, it kept trying to grab the first character before any of the pipes, kinda ruining things!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 15:01:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532817#M4413</guid>
      <dc:creator>jacqu3sy</dc:creator>
      <dc:date>2020-12-11T15:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields between pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532847#M4419</link>
      <description>&lt;P&gt;Sorry - Silly mistake in my regex (which I have now corrected) try the following. Serves me right for not testing it!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;rex field=Subject "(?P&amp;lt;number&amp;gt;[^\|]+)\|(?P&amp;lt;id&amp;gt;[^\|]+)\|(?P&amp;lt;ip&amp;gt;[^\|]+)\|(?P&amp;lt;email&amp;gt;[^\|]+)\|(?P&amp;lt;subject&amp;gt;[^$]+)"&lt;/LI-CODE&gt;&lt;P&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 16:22:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532847#M4419</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2020-12-11T16:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields between pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532848#M4420</link>
      <description>&lt;P&gt;Perfect. Works like a charm! Many thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 16:48:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532848#M4420</guid>
      <dc:creator>jacqu3sy</dc:creator>
      <dc:date>2020-12-11T16:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields between pipe</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532851#M4421</link>
      <description>Thanks don't forgot to upvote too if I helped!</description>
      <pubDate>Fri, 11 Dec 2020 17:18:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Regex-to-extract-fields-between-pipe/m-p/532851#M4421</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2020-12-11T17:18:13Z</dc:date>
    </item>
  </channel>
</rss>

