<?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: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310152#M93041</link>
    <description>&lt;P&gt;There is no way to do KVP matching with &lt;CODE&gt;rex&lt;/CODE&gt; (yes, I tested the &lt;CODE&gt;_KEY_1&lt;/CODE&gt;) but you can easily do it if you put it in &lt;CODE&gt;transfoms.conf&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;REGEX and the FORMAT attribute:

&lt;UL&gt;
&lt;LI&gt;Name-capturing groups in the REGEX are extracted directly to fields.
This means that you do not need to specify the FORMAT attribute for
simple field extraction cases (see the description of FORMAT, below).&lt;/LI&gt;
&lt;LI&gt;If the REGEX extracts both the field name and its corresponding field
value, you can use the following special capturing groups if you want to
skip specifying the mapping in FORMAT:
&lt;EM&gt;KEY&lt;/EM&gt;&lt;STRING&gt;, &lt;EM&gt;VAL&lt;/EM&gt;&lt;STRING&gt;.&lt;/STRING&gt;&lt;/STRING&gt;&lt;/LI&gt;
&lt;LI&gt;For example, the following are equivalent:&lt;/LI&gt;
&lt;LI&gt;Using FORMAT:
    * REGEX  = ([a-z]+)=([a-z]+)
    * FORMAT = $1::$2&lt;/LI&gt;
&lt;LI&gt;Without using FORMAT
    * REGEX  = (?&amp;lt;_KEY_1&amp;gt;[a-z]+)=(?&amp;lt;_VAL_1&amp;gt;[a-z]+)&lt;/LI&gt;
&lt;LI&gt;When using either of the above formats, in a search-time extraction,
the regex will continue to match against the source text, extracting
as many fields as can be identified in the source text.&lt;/LI&gt;
&lt;/UL&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;So for you, it is like this:&lt;/P&gt;

&lt;P&gt;In props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[MyFunkySourcetype]
TRANSFORMS-MyFunkyKVP = MyFunkyKVP
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In transforms.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[MyFunkyKVP]
REGEX = [\&amp;gt;\:]*\s+(.*?)\:?\s\&amp;lt;(.+?)\&amp;gt;
FORMAT = $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 12:55:44 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2020-09-29T12:55:44Z</dc:date>
    <item>
      <title>Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310149#M93038</link>
      <description>&lt;P&gt;I am attempting to parse a solaris log file into key/value pairs. The log is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;pam_vas: Authentication &amp;lt;succeeded&amp;gt; for &amp;lt;active directory&amp;gt; user: &amp;lt;bobtheperson&amp;gt; account: &amp;lt;bobtheperson@com.com&amp;gt; reason: &amp;lt;N/A&amp;gt; Access cont(upn): &amp;lt;bob&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result I am looking for will be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Authentication = succeeded
for = active directory
user = bobtheperson
account = bobtheperson@com.com
reason = N/A
Access cont(upn) = bob
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My testing shows that the expression &lt;CODE&gt;[\&amp;gt;\:]*\s+(.*?)\:?\s\&amp;lt;(.+?)\&amp;gt;&lt;/CODE&gt; should work.&lt;BR /&gt;
&lt;A href="http://regexr.com/3fatg"&gt;http://regexr.com/3fatg&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In Splunk, i put this regular expression into a search that returned the log in question.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mysearch | rex field=_raw "[\&amp;gt;\:]*\s+(.*?)\:?\s\&amp;lt;(.+?)\&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It returned an error:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Error in rex command. The regex does&lt;BR /&gt;
not extract anything. It should&lt;BR /&gt;
specify at least one named group.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Can you help me turn this into an actual key/value pair list of results?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310149#M93038</guid>
      <dc:creator>oliverj</dc:creator>
      <dc:date>2017-02-17T17:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310150#M93039</link>
      <description>&lt;P&gt;You have to give the field a name in your capture group.. &lt;/P&gt;

&lt;P&gt;Add &lt;CODE&gt;(?&amp;lt;FIELDNAME&amp;gt;)&lt;/CODE&gt; to your capture group and it will work in Splunk&lt;/P&gt;

&lt;P&gt;try something like this &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;mysearch | rex field=_raw "[\&amp;gt;\:]*\s+(?&amp;lt;Field1&amp;gt;.*?)\:?\s\&amp;lt;(?&amp;lt;Field2&amp;gt;.+?)\&amp;gt;"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:38:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310150#M93039</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2017-02-17T17:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310151#M93040</link>
      <description>&lt;P&gt;It runs, but no matches.&lt;BR /&gt;
And when I put it into "Field Extractor", the Field1 and Field2 tabs are empty as well.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 18:11:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310151#M93040</guid>
      <dc:creator>oliverj</dc:creator>
      <dc:date>2017-02-17T18:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310152#M93041</link>
      <description>&lt;P&gt;There is no way to do KVP matching with &lt;CODE&gt;rex&lt;/CODE&gt; (yes, I tested the &lt;CODE&gt;_KEY_1&lt;/CODE&gt;) but you can easily do it if you put it in &lt;CODE&gt;transfoms.conf&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;REGEX and the FORMAT attribute:

&lt;UL&gt;
&lt;LI&gt;Name-capturing groups in the REGEX are extracted directly to fields.
This means that you do not need to specify the FORMAT attribute for
simple field extraction cases (see the description of FORMAT, below).&lt;/LI&gt;
&lt;LI&gt;If the REGEX extracts both the field name and its corresponding field
value, you can use the following special capturing groups if you want to
skip specifying the mapping in FORMAT:
&lt;EM&gt;KEY&lt;/EM&gt;&lt;STRING&gt;, &lt;EM&gt;VAL&lt;/EM&gt;&lt;STRING&gt;.&lt;/STRING&gt;&lt;/STRING&gt;&lt;/LI&gt;
&lt;LI&gt;For example, the following are equivalent:&lt;/LI&gt;
&lt;LI&gt;Using FORMAT:
    * REGEX  = ([a-z]+)=([a-z]+)
    * FORMAT = $1::$2&lt;/LI&gt;
&lt;LI&gt;Without using FORMAT
    * REGEX  = (?&amp;lt;_KEY_1&amp;gt;[a-z]+)=(?&amp;lt;_VAL_1&amp;gt;[a-z]+)&lt;/LI&gt;
&lt;LI&gt;When using either of the above formats, in a search-time extraction,
the regex will continue to match against the source text, extracting
as many fields as can be identified in the source text.&lt;/LI&gt;
&lt;/UL&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;So for you, it is like this:&lt;/P&gt;

&lt;P&gt;In props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[MyFunkySourcetype]
TRANSFORMS-MyFunkyKVP = MyFunkyKVP
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In transforms.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[MyFunkyKVP]
REGEX = [\&amp;gt;\:]*\s+(.*?)\:?\s\&amp;lt;(.+?)\&amp;gt;
FORMAT = $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:55:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310152#M93041</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-09-29T12:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310153#M93042</link>
      <description>&lt;P&gt;Event type has been defined as "foo". All configuration taking place in etc/system/local&lt;BR /&gt;
Tested:&lt;BR /&gt;
1)&lt;BR /&gt;
props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[foo]
EXTRACT-MyFunkyKVP = [\&amp;gt;\:]*\s+(?&amp;lt;_KEY_1&amp;gt;.*?)\:?\s\&amp;lt;(?&amp;lt;_KEY_2&amp;gt;.+?)\&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Nothing in transforms.conf.&lt;/P&gt;

&lt;P&gt;2)&lt;BR /&gt;
props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [foo]
 TRANSFORMS-MyFunkyKVP = MyFunkyKVP
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [MyFunkyKVP]
 REGEX = [\&amp;gt;\:]*\s+(.*?)\:?\s\&amp;lt;(.+?)\&amp;gt;
 FORMAT = $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Neither way seems to generate any result (Searching in verbose mode)&lt;/P&gt;

&lt;P&gt;btool list against my props and transforms make it look like the conf files are applying against sourcetype:foo&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 19:57:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310153#M93042</guid>
      <dc:creator>oliverj</dc:creator>
      <dc:date>2017-02-20T19:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310154#M93043</link>
      <description>&lt;P&gt;Switch &lt;CODE&gt;TRANSFORMS-&lt;/CODE&gt; to &lt;CODE&gt;REPORT-&lt;/CODE&gt; to make it apply to ALL events (indexed in the past and in the future) at search-time by deploying on the Search Head.  The way that you have it now will only apply to events at index-time (i.e. events indexed after you deploy the new configurations and restart splunkd on the indexers).&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 20:19:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310154#M93043</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-02-20T20:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310155#M93044</link>
      <description>&lt;P&gt;Nevermind! my regular expression didn't account for any timestamps or other headers (im very new to regex stuff), only the body of the message.&lt;BR /&gt;
I edited an event to remove header, and it did some extractions. So, i know that the REPORT- is indeed working. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 20:46:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/310155#M93044</guid>
      <dc:creator>oliverj</dc:creator>
      <dc:date>2017-02-20T20:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why is my regular expression not working in the rex command? It has been tested as a standalone regex outside of spl</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/525652#M148357</link>
      <description>&lt;P&gt;Hey,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually i am in the same problem, and i tested this technic, it works pretty good.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's the right response :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;U&gt;index=pan_logs sourcetype=pan:system event_id="auth-fail" | rex field=description "user\s'(?&amp;lt;user&amp;gt;\w+)'\."&lt;/U&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;you can see exactely how in this video :&amp;nbsp;&lt;A href="https://www.youtube.com/watch?v=ppSxpzK2sj8&amp;amp;ab_channel=Splunk%26MachineLearning" target="_blank"&gt;https://www.youtube.com/watch?v=ppSxpzK2sj8&amp;amp;ab_channel=Splunk%26MachineLearning&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to close this discussion!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 23:41:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-my-regular-expression-not-working-in-the-rex-command-It/m-p/525652#M148357</guid>
      <dc:creator>badr_boukari</dc:creator>
      <dc:date>2020-10-20T23:41:51Z</dc:date>
    </item>
  </channel>
</rss>

