<?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 to match everything after the last occurence of a character in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-match-everything-after-the-last-occurence-of-a/m-p/200224#M58041</link>
    <description>&lt;P&gt;What about this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| rex "(\[[^\]]+\]\s?)+(?&amp;lt;logLevel&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval _raw = "[thread] [timestamp] [transactionID] LOGLEVEL1 {moreNonsense}"
| rex "(\[[^\]]+\]\s?)+(?&amp;lt;logLevel&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;logLevel = LOGLEVEL1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval _raw = "[thread] [timestamp] LOGLEVEL2 [transactionID] {moreNonsense}"
| rex "(\[[^\]]+\]\s?)+(?&amp;lt;logLevel&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;logLevel = LOGLEVEL2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Jun 2016 20:04:56 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-06-07T20:04:56Z</dc:date>
    <item>
      <title>Regex to match everything after the last occurence of a character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-match-everything-after-the-last-occurence-of-a/m-p/200222#M58039</link>
      <description>&lt;P&gt;I did not anticipate I'd struggle this much for what seemed like such a simple task.&lt;/P&gt;

&lt;P&gt;The logs I am trying to parse have all sorts of crap sandwiched into [brackets]. &lt;/P&gt;

&lt;P&gt;Examples:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[thread] [timestamp] [transactionID] logLevel {moreNonsense}

[thread] [timestamp] logLevel [transactionID] {moreNonsense}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want the logLevel. To say, I want all the text after the last occurrence of &lt;CODE&gt;]&lt;/CODE&gt;, but before the first occurrence of &lt;CODE&gt;}&lt;/CODE&gt;&lt;BR /&gt;
Using regular expressions, how can I state to only return the string following that last &lt;CODE&gt;]&lt;/CODE&gt;. There is no consistency in the character length or type of each bracketed field, there is also a variable number of bracket sets in each event, prior to the logLevel (2, 3 or 4 sets, dependent on the log source).  &lt;/P&gt;

&lt;P&gt;Each attempt I have made has yielded a logLevel value of everything following the very first closed bracket &lt;CODE&gt;]&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 19:43:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-match-everything-after-the-last-occurence-of-a/m-p/200222#M58039</guid>
      <dc:creator>bcatwork</dc:creator>
      <dc:date>2016-06-07T19:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to match everything after the last occurence of a character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-match-everything-after-the-last-occurence-of-a/m-p/200223#M58040</link>
      <description>&lt;P&gt;If log_level can be multiple words, use this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.*\]\s*(?&amp;lt;log_level&amp;gt;[^\{]+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR if it is always single word, use this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.*\]\s*(?&amp;lt;log_level&amp;gt;\w+)\s*\{
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR if log_level is a finite list, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;log_level&amp;gt;INFO|WARN|DEBUG|CRITICAL)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2016 20:02:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-match-everything-after-the-last-occurence-of-a/m-p/200223#M58040</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-06-07T20:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to match everything after the last occurence of a character</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-match-everything-after-the-last-occurence-of-a/m-p/200224#M58041</link>
      <description>&lt;P&gt;What about this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| rex "(\[[^\]]+\]\s?)+(?&amp;lt;logLevel&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval _raw = "[thread] [timestamp] [transactionID] LOGLEVEL1 {moreNonsense}"
| rex "(\[[^\]]+\]\s?)+(?&amp;lt;logLevel&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;logLevel = LOGLEVEL1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval _raw = "[thread] [timestamp] LOGLEVEL2 [transactionID] {moreNonsense}"
| rex "(\[[^\]]+\]\s?)+(?&amp;lt;logLevel&amp;gt;\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;logLevel = LOGLEVEL2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2016 20:04:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-match-everything-after-the-last-occurence-of-a/m-p/200224#M58041</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-06-07T20:04:56Z</dc:date>
    </item>
  </channel>
</rss>

