<?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 help! (easy one) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101729#M26272</link>
    <description>&lt;P&gt;Is there any way you could explain what you did to me? Because I have to build extractions for the data in the separate sections (separated by -) in that bracket.&lt;/P&gt;

&lt;P&gt;Awesome, fast answer btw.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jul 2012 21:30:58 GMT</pubDate>
    <dc:creator>beaunewcomb</dc:creator>
    <dc:date>2012-07-17T21:30:58Z</dc:date>
    <item>
      <title>Regex help! (easy one)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101725#M26268</link>
      <description>&lt;P&gt;I need to extract fields from a set of results with inconsistent formatting. I think this would be easy for a regex pro. &lt;/P&gt;

&lt;P&gt;Here are two events:&lt;/P&gt;

&lt;P&gt;Jul 17 15:44:01 hostname 192.168.0.1 [st2-b3-inter-d005][system][error] trans(119657588)[192.168.0.2]: Unable to open URL &lt;/P&gt;

&lt;P&gt;Jul 17 15:44:01 hostname 192.168.0.1 [network][error] trans(2064751791): Host connection could not be established&lt;/P&gt;

&lt;P&gt;I need multiple extractions for the data within the first set of brackets (separated by the dash) in event 1. You'll see that event 2 doesn't contain this type of data at all.&lt;/P&gt;

&lt;P&gt;Basically I need a regex that says "Match everything between the first [ and first - but not if there are more than 3 characters before the -"&lt;/P&gt;

&lt;P&gt;I'm basically a regex noob!&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 21:11:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101725#M26268</guid>
      <dc:creator>beaunewcomb</dc:creator>
      <dc:date>2012-07-17T21:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Regex help! (easy one)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101726#M26269</link>
      <description>&lt;P&gt;This should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[([^-]{0,3})-
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2012 21:20:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101726#M26269</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-07-17T21:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Regex help! (easy one)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101727#M26270</link>
      <description>&lt;P&gt;Wow, fast response! How would I use that in the field extractor?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 21:23:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101727#M26270</guid>
      <dc:creator>beaunewcomb</dc:creator>
      <dc:date>2012-07-17T21:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Regex help! (easy one)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101728#M26271</link>
      <description>&lt;P&gt;The field extractor wants a named extraction for FIELDNAME if I remember correctly, so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[(?P&amp;lt;FIELDNAME&amp;gt;[^-]{0,3})-
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2012 21:24:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101728#M26271</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-07-17T21:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Regex help! (easy one)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101729#M26272</link>
      <description>&lt;P&gt;Is there any way you could explain what you did to me? Because I have to build extractions for the data in the separate sections (separated by -) in that bracket.&lt;/P&gt;

&lt;P&gt;Awesome, fast answer btw.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 21:30:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101729#M26272</guid>
      <dc:creator>beaunewcomb</dc:creator>
      <dc:date>2012-07-17T21:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Regex help! (easy one)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101730#M26273</link>
      <description>&lt;P&gt;I did nothing to you! &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;No, sure. The regex first looks for the opening bracket, which has to be escaped because [ is a special character in regexes otherwise.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then the matching starts. We're looking for characters that are NOT the dash sign.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[([^-]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Match if we find at least 0 and at most 3 non-dash characters.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[([^-]{0,3}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;End our matching group, and only match if this is immediately followed by a dash sign.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;\[([^-]{0,3})-
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope that sheds some light on how the regex is built step by step.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 21:36:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101730#M26273</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-07-17T21:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Regex help! (easy one)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101731#M26274</link>
      <description>&lt;P&gt;Hahah you helped me!&lt;/P&gt;

&lt;P&gt;You rock.. thanks a lot. I need to get this regex stuff down.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2012 22:24:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-help-easy-one/m-p/101731#M26274</guid>
      <dc:creator>beaunewcomb</dc:creator>
      <dc:date>2012-07-17T22:24:37Z</dc:date>
    </item>
  </channel>
</rss>

