<?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 get rex to stop after the first value found? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264898#M79561</link>
    <description>&lt;P&gt;Ok, seems that my rex field string above is being clipped by the forum for some reason.  I define the ALERTTYPE field in the string.&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2016 20:48:51 GMT</pubDate>
    <dc:creator>rob_gibson</dc:creator>
    <dc:date>2016-10-18T20:48:51Z</dc:date>
    <item>
      <title>How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264894#M79557</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am building a table and supplying values from search.  One of the values exists multiple times within each event.  I want rex to stop after the first value returned.  I thought that may be un greedy but I can't seem to nail down the proper syntax.  &lt;/P&gt;

&lt;P&gt;I'm grateful for any help.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=statement "(?[^\s]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This rex returns two of the same values into my table for each line. (ALERT, ALERT).  I want a single line, therefore I require a single result to be extracted.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt;&lt;BR /&gt;
I don't wish to waste anybody's time further on this -  I am convinced the issue is with the 'statement' field.  A simple query (no rex, etc) consistently produces two values on two lines when 'statement' is displayed in a table.  Splunk returns that there are only two results, but each result has two lines (4 total).  Other fields for example 'RecordNumber' produce a single line.  &lt;/P&gt;

&lt;P&gt;I have no clue why this is happening but it has nothing to do with rex.&lt;/P&gt;

&lt;P&gt;**Turns out the problem was a multivalue field as other's suggested.  I modified my search string to eliminate the duplicates;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| nomv statement | rex field=statement "(?&amp;lt;ALERTTYPE&amp;gt;[^\s]+)" ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2016 20:17:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264894#M79557</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-18T20:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264895#M79558</link>
      <description>&lt;P&gt;Can we have some sample data on which this regex is run?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 20:31:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264895#M79558</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-18T20:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264896#M79559</link>
      <description>&lt;P&gt;As @somesoni2 said.. We cant help until we get some sample data&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 20:34:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264896#M79559</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2016-10-18T20:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264897#M79560</link>
      <description>&lt;P&gt;The statement field contains the string I'm trying to extract from;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;statement:ALTER DATABASE [DBA] MODIFY FILE ( NAME = N'DBA', FILEGROWTH = 1048576KB )&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;When I create the table I am consistently getting two values for the first word in the string, ALTER;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;|table ComputerName, "ALERTTYPE", Database, TimeStamp, UserID, EventCode&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I can't seem to edit my question, but the reg string above is incomplete - my apologies;&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;rex field=statement "(?[^\s]+)"&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 20:47:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264897#M79560</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-18T20:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264898#M79561</link>
      <description>&lt;P&gt;Ok, seems that my rex field string above is being clipped by the forum for some reason.  I define the ALERTTYPE field in the string.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 20:48:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264898#M79561</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-18T20:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264899#M79562</link>
      <description>&lt;P&gt;How about using a quantifier? This will restrict it to the first match&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; rex field=statement "(?[^\s]{1})"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your use of the "+" (plus sign) indicates to 'regex', &lt;STRONG&gt;one or more&lt;/STRONG&gt; matches&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 21:11:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264899#M79562</guid>
      <dc:creator>adamsaul</dc:creator>
      <dc:date>2016-10-18T21:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264900#M79563</link>
      <description>&lt;P&gt;If you only extracting the first word, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=statement "(?&amp;lt;ALERTTYPE&amp;gt;\w+)" max_match=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's a runanywhere sample&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval statement="ALTER ALTER DATABASE [DBA] MODIFY FILE ( NAME = N'DBA', FILEGROWTH = 1048576KB )" | rex field=statement "(?&amp;lt;ALERTTYPE&amp;gt;\w+)" max_match=1 | table statement ALERTTYPE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2016 21:19:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264900#M79563</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-10-18T21:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264901#M79564</link>
      <description>&lt;P&gt;Ok, these did not produce any value for the AlertType field.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 15:07:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264901#M79564</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T15:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264902#M79565</link>
      <description>&lt;P&gt;This still returns two values, but only the letter 'A', not the entire word 'Alert'.  &lt;/P&gt;

&lt;P&gt;I'm starting to wonder if the issue is unrelated to the rex statement (ie; maybe the word 'ALERT' only appears once for each event and the return value is being duplicated for another reason.)&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 15:09:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264902#M79565</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T15:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264903#M79566</link>
      <description>&lt;P&gt;Can you provide some sample data and the data you want extracted?&lt;/P&gt;

&lt;P&gt;Be sure to use the code sample format when you post&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 15:18:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264903#M79566</guid>
      <dc:creator>adamsaul</dc:creator>
      <dc:date>2016-10-19T15:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264904#M79567</link>
      <description>&lt;P&gt;data sample above (yesterday) in response to skoelpin.  I'll try to post it in the question body.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 17:00:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264904#M79567</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T17:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264905#M79568</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;rex field=statement "(^\w+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Oct 2016 17:34:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264905#M79568</guid>
      <dc:creator>adamsaul</dc:creator>
      <dc:date>2016-10-19T17:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264906#M79569</link>
      <description>&lt;P&gt;I think I needed to change this slightly as Splunk returned "Error in 'rex' command: The regex '(^\w+)' does not extract anything. It should specify at least one named group. Format: (?...). "&lt;/P&gt;

&lt;P&gt;So I changed to;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=statement "(?&amp;lt;ALERTTYPE&amp;gt;[^\w+])"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And that produced zero results for statement&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 17:46:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264906#M79569</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T17:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264907#M79570</link>
      <description>&lt;P&gt;Sorry about that. I left off the named group.&lt;/P&gt;

&lt;P&gt;I'm not sure why that is not matching, @sundareshr appears to working. I just added a bit for the beginning of the line.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 17:49:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264907#M79570</guid>
      <dc:creator>adamsaul</dc:creator>
      <dc:date>2016-10-19T17:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264908#M79571</link>
      <description>&lt;P&gt;If I go back to my original rex;&lt;BR /&gt;
    rex field=statement "(?&lt;ALERTTYPE&gt;[^\s]+)"&lt;BR /&gt;
I do get a full word 'Alter' but it appears 2x.  Looking at the event data, I do not see the word Alter more than once, so perhaps my rex is not the issue?&lt;/ALERTTYPE&gt;&lt;/P&gt;

&lt;P&gt;Scrubbed event data (complete);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;10/17/16
    12:20:25.000 PM     
    10/17/2016 12:20:25 PM
    LogName=Application
    SourceName=MSSQL$OTPMSSQL
    EventCode=33205
    EventType=0
    Type=Information
    ComputerName=hostname.domain.com
    TaskCategory=None
    OpCode=None
    RecordNumber=904492
    Keywords=Audit Success, Classic
    Message=Audit event: event_time:2016-10-17 16:20:24.1512330
    sequence_number:1
    action_id:AL  
    succeeded:true
    permission_bitmask:0
    is_column_permission:false
    session_id:136
    server_principal_id:276
    database_principal_id:1
    target_server_principal_id:0
    target_database_principal_id:0
    object_id:8
    class_type:DB
    session_server_principal_name:domain\userID
    server_principal_name:domain\userID
    server_principal_sid:010500000000000515000000093a2a2426761e2f43170a326b1e0000
    database_principal_name:dbo
    target_server_principal_name:
    target_server_principal_sid:
    target_database_principal_name:
    server_instance_name:hostname\SQL
    database_name:DBA
    schema_name:
    object_name:DBA
    statement:ALTER DATABASE [DBA] MODIFY FILE ( NAME = N'DBA_log', FILEGROWTH = 1048576KB )
    additional_information:
    .
    Collapse

        ComputerName = hostname.domain.com
        EventCode = 33205
        host = hostname
        source = WinEventLog:Application
        sourcetype = WinEventLog:Application   
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Oct 2016 17:55:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264908#M79571</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T17:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264909#M79572</link>
      <description>&lt;P&gt;I think it is giving you the &lt;STRONG&gt;match&lt;/STRONG&gt; and sub-match or the &lt;STRONG&gt;match array&lt;/STRONG&gt;, which is why it appears twice.&lt;/P&gt;

&lt;P&gt;Does appending &lt;STRONG&gt;max_match=1&lt;/STRONG&gt; to the end of your 'rex' search help?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 18:06:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264909#M79572</guid>
      <dc:creator>adamsaul</dc:creator>
      <dc:date>2016-10-19T18:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264910#M79573</link>
      <description>&lt;P&gt;If you like to get the first word of a string inn to a variable, this should do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ALTER DATABASE [DBA] MODIFY FILE ( NAME = N'DBA', FILEGROWTH = 1048576KB )
your search | rex "^(?&amp;lt;AlertType&amp;gt;\S+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Gives &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;AlertType=ALTER
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;^&lt;/CODE&gt; in the regex tells to get text from the line until the first space.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 18:12:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264910#M79573</guid>
      <dc:creator>lakromani</dc:creator>
      <dc:date>2016-10-19T18:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264911#M79574</link>
      <description>&lt;P&gt;Sort of.  By appending your suggestion I no longer get two lines, but I do not get a value 'Alter' either.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=statement "(?&amp;lt;field1&amp;gt;[^\s]+) max_match=1"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Oct 2016 18:18:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264911#M79574</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T18:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264912#M79575</link>
      <description>&lt;P&gt;Here is the result in the table;&lt;BR /&gt;
&lt;IMG src="http://i94.photobucket.com/albums/l84/Cybergy/Capture_zpstfr9xmyb.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 18:22:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264912#M79575</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T18:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get rex to stop after the first value found?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264913#M79576</link>
      <description>&lt;P&gt;I had to change that a bit, as the value is extracted from the 'statement' field;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=statement "^(?&amp;lt;field1&amp;gt;\S+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But the result is still two lines,&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 18:34:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-rex-to-stop-after-the-first-value-found/m-p/264913#M79576</guid>
      <dc:creator>rob_gibson</dc:creator>
      <dc:date>2016-10-19T18:34:53Z</dc:date>
    </item>
  </channel>
</rss>

