<?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: rex not working as expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328581#M97809</link>
    <description>&lt;P&gt;Your spl line of &lt;CODE&gt;rex&lt;/CODE&gt; is getting interpreted as below which is making it see it as a misplaced quote after two pairs of quotes:&lt;BR /&gt;
&lt;CODE&gt;index=x ... | rex&lt;/CODE&gt;   &lt;CODE&gt;"^(?:[^"&lt;/CODE&gt;       &lt;CODE&gt;\n]*&lt;/CODE&gt;         &lt;CODE&gt;"){3}(?P&amp;lt;index_ks&amp;gt;[^"&lt;/CODE&gt;    &lt;CODE&gt;]+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Like @HiroshiSatoh mentioned the quotes shall be escaped like &lt;CODE&gt;\"&lt;/CODE&gt; to make it as &lt;CODE&gt;index=x ... | rex "^(?:[^\"\n]*\"){3}(?P&amp;lt;index_ks&amp;gt;[^\"]+)"&lt;/CODE&gt; if you feel your regex is working fine on regex101.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Sep 2017 02:08:36 GMT</pubDate>
    <dc:creator>gokadroid</dc:creator>
    <dc:date>2017-09-11T02:08:36Z</dc:date>
    <item>
      <title>rex not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328579#M97807</link>
      <description>&lt;P&gt;What is wrong with this rex?? This is the rex that the system gives me when I do a extract fields option.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=x ... | rex "^(?:[^"\n]*"){3}(?P&amp;lt;index_ks&amp;gt;[^"]+)"&lt;/CODE&gt;&lt;BR /&gt;
I am getting &lt;BR /&gt;
&lt;CODE&gt;Mismatched ']'.&lt;/CODE&gt; when I do the search.&lt;/P&gt;

&lt;P&gt;This is the regex working  here&lt;BR /&gt;
&lt;A href="https://regex101.com/r/LxVFbf/1"&gt;https://regex101.com/r/LxVFbf/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Another way to write it is like this, although not as generic: &lt;BR /&gt;
&lt;CODE&gt;index=* | rex "index="(?P&amp;lt;index_ks&amp;gt;.*)";"&lt;/CODE&gt;&lt;BR /&gt;
which works see here:&lt;BR /&gt;
&lt;A href="https://regex101.com/r/YCn7h6/1"&gt;https://regex101.com/r/YCn7h6/1&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;However, the result single quotes at start and end e.g. &lt;CODE&gt;'result1' 'result2'&lt;/CODE&gt; in Splunk, but not in the regex101 example. &lt;/P&gt;

&lt;P&gt;Would like to understand this better.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 00:49:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328579#M97807</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2017-09-11T00:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: rex not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328580#M97808</link>
      <description>&lt;P&gt;It is necessary to escape double quotes.&lt;/P&gt;

&lt;P&gt;ex.&lt;BR /&gt;
    | rex "^(?:[^\"\n]*\"){3}(?P&lt;INDEX_KS&gt;[^\"]+)"&lt;/INDEX_KS&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 01:53:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328580#M97808</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2017-09-11T01:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: rex not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328581#M97809</link>
      <description>&lt;P&gt;Your spl line of &lt;CODE&gt;rex&lt;/CODE&gt; is getting interpreted as below which is making it see it as a misplaced quote after two pairs of quotes:&lt;BR /&gt;
&lt;CODE&gt;index=x ... | rex&lt;/CODE&gt;   &lt;CODE&gt;"^(?:[^"&lt;/CODE&gt;       &lt;CODE&gt;\n]*&lt;/CODE&gt;         &lt;CODE&gt;"){3}(?P&amp;lt;index_ks&amp;gt;[^"&lt;/CODE&gt;    &lt;CODE&gt;]+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Like @HiroshiSatoh mentioned the quotes shall be escaped like &lt;CODE&gt;\"&lt;/CODE&gt; to make it as &lt;CODE&gt;index=x ... | rex "^(?:[^\"\n]*\"){3}(?P&amp;lt;index_ks&amp;gt;[^\"]+)"&lt;/CODE&gt; if you feel your regex is working fine on regex101.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 02:08:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328581#M97809</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2017-09-11T02:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: rex not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328582#M97810</link>
      <description>&lt;P&gt;Here is the search with rex.  I am lost why it's not working to exact the user.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ldap sourcetype="ldap:audit" 
| rex "\s\w{2}=\w\d(?&amp;lt;user&amp;gt;[^,]+)" 
| stats count by user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is the event string:&lt;/P&gt;

&lt;P&gt;time: 20200423225406&lt;BR /&gt;
result: 0&lt;BR /&gt;
changetype: modify&lt;BR /&gt;
replace: lastLoginTime&lt;BR /&gt;
lastLoginTime: 20200423225402Z&lt;BR /&gt;
modifiersName: cn=g5-bdent,ou=srveauth,dc=june,dc=gov&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 22:57:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-not-working-as-expected/m-p/328582#M97810</guid>
      <dc:creator>youngsuh</dc:creator>
      <dc:date>2020-04-23T22:57:12Z</dc:date>
    </item>
  </channel>
</rss>

